iOS开发_唤起拨打电话,打电话功能

1、UIWebView唤起

  • 效果
    • 打电话前会有提示,打完电话后会回到原来的程序。系统版本13.4.1,唤起提示框,速度较慢。使用UIWebView唤起,不确定具体应用场景。
NSString *phoneNumber = @"10086";
NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"tel:%@", phoneNumber];
UIWebView *callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];

2、UIApplication唤起

  • 效果
    • 打电话前会有提示,打完电话后会回到原来的程序。系统版本13.4.1,唤起提示框,速度正常。
NSString *phoneNumber = @"10086";
NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"tel:%@", phoneNumber];
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:str];
if (@available(iOS 10.0, *)) {
    [application openURL:URL options:@{} completionHandler:^(BOOL success) {
        // OpenSuccess=选择 呼叫 为 1  选择 取消 为0
        NSLog(@"OpenSuccess=%d",success);

    }];
}
else {
// Fallback on earlier versions
}
posted @ 2020-07-22 23:01  CH520  阅读(863)  评论(0编辑  收藏  举报