iOS真机打电话

打电话

@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真机打电话)