iOS 拨打电话(OC和Swift)

OC 版本


/**
 * 拨打电话-UIApplication
 */
+ (void)calltelpro:(NSString *)telPhone{
    NSString *urlStr = [NSString stringWithFormat:@"telprompt://%@",telPhone];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSLog(@"application 打电话telprompt: %@", urlStr);
    [[UIApplication sharedApplication] openURL:url];
}

/**
 * 拨打电话-UIApplication
 */
+ (void)calltel:(NSString *)telPhone{
    NSString *urlStr = [NSString stringWithFormat:@"tel://%@",telPhone];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSLog(@"application 打电话tel: %@", urlStr);
    [[UIApplication sharedApplication] openURL:url];
}

在上方两种使用UIApplication实际可用,webView方式不可用。

Swift 版本


class func callPhoneTel(phone : String){
    let  phoneUrlStr = "tel://"+phone
    if UIApplication.shared.canOpenURL(URL(string: phoneUrlStr)!
    {
        UIApplication.shared.openURL(URL(string: phoneUrlStr)!)
    }
}

class func callPhoneTelpro(phone : String){
    let  phoneUrlStr = "telprompt://"+phone
    if UIApplication.shared.canOpenURL(URL(string: phoneUrlStr)!
    {
        UIApplication.shared.openURL(URL(string: phoneUrlStr)!)
    }
}


你可能感兴趣的:(iOS 拨打电话(OC和Swift))