iOS上带有主题标签的电话号码

如何在iOS上拨打此号码* 199 * 123456789#?

我使用了以下代码,但它不起作用。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:*199*123456789#"]]; 

引用URL方案文档

为防止用户恶意重定向电话或更改电话或帐户的行为,电话应用程序支持tel方案中的大多数但不是全部特殊字符。 具体来说,如果URL包含*或#字符,则电话应用程序不会尝试拨打相应的电话号码。

从我所看到的,它看起来像你可以使用的唯一方案是有效的:

 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890p111"]]; 

拨打分机号码。

*替换为%2A ,将#替换为%23

 NSURL *tel = [NSURL URLWithString:@"tel:%2A199%2A123456789%23"]; [[UIApplication sharedApplication] openURL:tel]; 

转发并修改我现在关闭的问题“ iOS – 我想拨打电话号码”#51234“在Xcode中使用telprompt ”:

至少从iOS 11开始, 可以使用#标签(#)或星号(*)拨打号码。

通过首先编码电话号码 ,然后添加tel:前缀,最后将结果字符串转换为URL,使用这些字符进行调用。

Swift 4,iOS 11

 // 1) set up the dial sequence as a String let dialSequence = "*199*123456789#" // 2) "percent encode" the dial sequence with the "URL Host Allowed" character set guard let encodedDialSequence = dialSequence.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else { print("Unable to encode the dial sequence.") return } // 3) add the `tel:` url scheme to the front of the encoded string // NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work. let dialURLString = "tel:\(encodedDialSequence)" // 4) set up the URL with the scheme+encoded number string guard let dialURL = URL(string: dialURLString) else { print("Couldn't convert the dial string into an URL.") return } // 5) dial the URL UIApplication.shared.open(dialURL, options: [:]) { success in if success { print("SUCCESSFULLY OPENED DIAL URL") } else { print("COULDN'T OPEN DIAL URL") } } 

Objective-C,iOS 11

 // 1) set up the dial sequence as a String NSString *dialSequence = @"*199*123456789#"; // 2) "percent encode" the dial sequence with the "URL Host Allowed" character set NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet]; NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed]; // 3) add the 'tel:' url scheme to the front of the encoded string // NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work. NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence]; // 4) set up the URL with the scheme+encoded number string NSURL *dialURL = [NSURL URLWithString:dialURLString]; // 5) set up an empty dictionary for the options parameter NSDictionary *optionsDict = [[NSDictionary alloc] init]; // 6) dial the URL [[UIApplication sharedApplication] openURL:dialURL options:optionsDict completionHandler:^(BOOL success) { if (success) { NSLog(@"SUCCESSFULLY OPENED DIAL URL"); } else { NSLog(@"COULDN'T OPEN DIAL URL"); } }]; 

您需要使用tel://而不仅仅是tel:

Interesting Posts