iOS真机打电话

2018-07-27  本文已影响8人  geekAppke

打电话

@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
上一篇下一篇

猜你喜欢

热点阅读