这个问题已经在这里有一个答案:
- 在iOS与包括hashtag电话呼叫号码 3回答
我想打电话给在Xcode使用telprompt电话号码“#51234”。
但telprompt是拒绝。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://#5%@", nzoneNum]]];
nzomeNum是 “1234”
这个问题已经在这里有一个答案:
我想打电话给在Xcode使用telprompt电话号码“#51234”。
但telprompt是拒绝。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://#5%@", nzoneNum]]];
nzomeNum是 “1234”
至少的iOS 11,一个可与包括hashtag(#)或星号(*)拨号号码。
通过第一编码的电话号码 ,然后加入让这些字符电话tel:
前缀,终于打开生成的字符串为URL。
迅速4,11的iOS
// set up the dial sequence
let nzoneNum = "1234"
let prefix = "#5"
let dialSequence = "\(prefix)\(nzoneNum)"
// "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
}
// add the `tel:` url scheme to the front of the encoded string
let dialURLString = "tel:\(encodedDialSequence)"
// set up the URL with the scheme/encoded number string
guard let dialURL = URL(string: dialURLString) else {
print("Couldn't make the dial string into an URL.")
return
}
// dial the URL
UIApplication.shared.open(dialURL, options: [:]) { success in
if success { print("SUCCESSFULLY OPENED DIAL URL") }
else { print("COULDN'T OPEN DIAL URL") }
}
客观-C,11的iOS
// set up the dial sequence
NSString *nzoneNum = @"1234";
NSString *prefix = @"#5";
NSString *dialSequence = [NSString stringWithFormat:@"%@%@", prefix, nzoneNum];
// set up the URL Host allowed character set, and "percent encode" the dial sequence
NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed];
// add the `tel` url scheme to the front of the encoded string
NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence];
// set up the URL with the scheme/encoded number string
NSURL *dialURL = [NSURL URLWithString:dialURLString];
// set up an empty dictionary for the options parameter
NSDictionary *optionsDict = [[NSDictionary alloc] init];
// 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"); }
}];
不幸的是,你不能让任何号码,包括一个主题标签调用。 苹果显然限制了这些电话: iPhoneURLScheme_Reference
为了防止用户恶意重定向电话或更改电话或账户的行为,将手机应用程序支持大多数,但不是全部,在电话方案的特殊字符。 具体而言,如果URL中包含*或#字符时,手机应用程序不尝试拨打相应的电话号码。