系统功能调用

判断功能是否可以使用

[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@""]];

参数书写具体调用的功能

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@""]];

封装方法 传入功能名称 调用功能

  • (void)appOpenUrl:(NSString *)urlStr{
    NSURL * url = [NSURL URLWithString:urlStr];
    UIApplication * app = [UIApplication sharedApplication];
    if ([app canOpenURL:url]) {
    [app openURL:url];
    }else{
    NSLog(@"error");
    }
    }

pragma mark -- 打电话

  • (IBAction)tell:(UIButton *)sender {
    [self appOpenUrl:@"tel://10086"];
    }

pragma mark -- 发短信

  • (IBAction)message:(UIButton *)sender {
    [self appOpenUrl:@"sms://10086"];
    }

pragma mark -- 发邮件

  • (IBAction)email:(UIButton *)sender {
    [self appOpenUrl:@"mailto://10086"];
    }

pragma mark -- 浏览器

  • (IBAction)browser:(UIButton *)sender {
    [self appOpenUrl:@"http://10086"];
    }

pragma mark -- 应用跳转

  • (IBAction)appJump:(UIButton *)sender {
    //添加跳转白名单的操作 LSApplicationQueriesSchemes Xcode7应用跳转
    }
    //application代理方法
    -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options
    {
    NSLog(@"接收到应用传值%@",url.absoluteString);
    return YES;
    }

你可能感兴趣的:(系统功能调用)