I want to call a phone number from ios native app
the code is like this:
NSString *allString = [NSString stringWithFormat:@"tel:%@",phoneNum];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]]
In IOS10.2, Some one can auto-call directly, but others got a confirm dialog.
So, what should I do to let all iphones can auto call directly?
Use in your viewcontroller
func doPhoneCall(_ number: String?) {
if var number = number {
number = number.replacingOccurrences(of: " ", with: "")
if let phoneCallURL = URL(string:"tel://\(number)") {
openURL(phoneCallURL)
}
}
}
func openURL(_ url: URL) {
let application = UIApplication.shared
if (application.canOpenURL(url)) {
application.openURL(url);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.