关于APP内跳转到QQ界面和直接拨打电话

我们在开发APP 的过程中会经常遇到这样的需求,跳转到客服QQ界面,拨打电话等,直接上代码

1.关于APP跳转到客服QQ界面

 // 空白的webview
   UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
    
    //1691838426 是QQ号
    
    NSString * string = @"mqq://im/chat?chat_type=wpa&uin=1691838426&version=1&src_type=web";
    
    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"shipping要打开你的QQ" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *callAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [actionSheet addAction:cancelAction];
    [actionSheet addAction:callAction];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:actionSheet animated:YES completion:nil];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:webView];
    
}else{
    
    UIAlertView*ale=[[UIAlertView alloc] initWithTitle:@"提示" message:@"您没有安装手机QQ,请安装手机QQ后重试,或用PC进行操作。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [ale show];
    
}

2.关于APP直接拨打电话又三种实现方式

  • 第一种:直接拨打电话,没有提示
    //拨打电话
    UIApplication *ac = [UIApplication sharedApplication];

      NSURL *url = [NSURL URLWithString:[@"tel://"   stringByAppendingString:@"你要放的电话号码"]];
    
      [ac openURL:url];
    
  • 第二种:打完电话后还会回到原来的程序,也会弹出提示,
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"你要放的电话号码"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];

  • 第三种: 打完电话后还会回到原来的程序,也会弹出提示,
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"你要放的电话号码"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

你可能感兴趣的:(关于APP内跳转到QQ界面和直接拨打电话)