我想拨打电话号码“#51234",在Xcode中使用telprompt [英] I want to call phone number "#51234" in Xcode use telprompt
本文介绍了我想拨打电话号码“#51234",在Xcode中使用telprompt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要使用telprompt拨打Xcode中的电话号码#51234".
I want to call phone number "#51234" in Xcode use telprompt.
但是telprompt拒绝了它.
but telprompt is reject it.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://#5%@", nzoneNum]]];
nzomeNum为"1234"
nzomeNum is "1234"
推荐答案
至少从iOS 11开始,一个可以拨打带有井号(#)或星号(*)的号码.
At least as of iOS 11, one can dial numbers with a hashtag (#) or asterisk (*).
首先用编码电话号码,然后添加tel:
前缀,最后将得到的字符串转换为URL,以使用这些字符进行呼叫.
Make calls with these characters by first encoding the phone number, then adding the tel:
prefix, and finally turning the resulting string into a URL.
Swift 4,iOS 11
// 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") }
}
Objective-C,iOS 11
// 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"); }
}];
这篇关于我想拨打电话号码“#51234",在Xcode中使用telprompt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文