美文网首页
iOS真机打电话

iOS真机打电话

作者: geekAppke | 来源:发表于2018-07-27 10:53 被阅读8次

打电话

@interface LOAppURLHandler : NSObject
+ (void)openApplicationByURLString:(NSString *)urlString;
+ (void)callTel:(NSString *)phoneNo;
@end

@implementation LOAppURLHandler
+ (void)openApplicationByURLString:(NSString *)urlString {
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    }
}

+ (void)callTel:(NSString *)phoneNo {
    if (TARGETED_DEVICE_IS_IPHONE)
    {
        NSString *dialURL = [[NSString alloc] initWithFormat:@"tel://%@", phoneNo];
        [[self class] openApplicationByURLString:dialURL];
    } else {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"此设备不支持电话功能!"
                                                           delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView performSelector:@selector(show) withObject:nil afterDelay:0.3];
    }
}
@end
#define TARGETED_DEVICE_IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone

相关文章

网友评论

      本文标题:iOS真机打电话

      本文链接:https://www.haomeiwen.com/subject/jeobmftx.html