iOS 三种打电话方式

打电话.gif

api

- (BOOL)openURL:(NSURL*)url NS_DEPRECATED_IOS(2_0, 10_0, "Please use openURL:options:completionHandler: instead") NS_EXTENSION_UNAVAILABLE_IOS("");
- (void)openURL:(NSURL*)url options:(NSDictionary *)options completionHandler:(void (^ __nullable)(BOOL success))completion NS_AVAILABLE_IOS(10_0) NS_EXTENSION_UNAVAILABLE_IOS("");

方案1: @"tel:%@"

    NSString * telStr = [NSString stringWithFormat:@"tel:%@",@"12306"];
     //iOS10以后
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telStr] options:@{UIApplicationOpenURLOptionsSourceApplicationKey : @YES} completionHandler:^(BOOL success) {
        }];
    } else {
        //iOS10以前
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telStr]];
    }

iOS10以前该方案直接就打电话,没有提示框,挂断后不返回到当前应用,iOS 10以后有提示框并且返回到当前应用,并且多了一个api
方案2: @"telprompt://%@"

    NSString * telStr = [NSString stringWithFormat:@"telprompt://%@",@"12306"];
       //iOS10以后
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telStr] options:@{UIApplicationOpenURLOptionsSourceApplicationKey : @YES} completionHandler:^(BOOL success) {
        }];
    } else {
        //iOS10以前
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telStr]];
    }

该方案有提示框并且返回到当前应用,但@"telprompt://%@"非正式在AppStore发布好像审核通过不了(待验证)
方案3:用UIWebView加载url

    NSString * telStr = [NSString stringWithFormat:@"tel:%@",@"12306"];
    UIWebView * webV = [[UIWebView alloc]init];
    [webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:telStr]]];
    [self.view addSubview:webV];

该方案有提示框并且返回到当前应用,但测试感觉响应相对较慢.

你可能感兴趣的:(iOS 三种打电话方式)