在浏览器中可以通过JS代码打开QQ并弹出聊天界面,一般作为客服QQ使用。而在移动端腾讯没有公布提供类似API,但是却可以使用schema模式来启动手机QQ
//qqNumber就是你要打开的QQ号码, 也就是你的客服号码。
NSString *qqNumber=@"1918263902";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqNumber]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
webView.delegate = self;
[webView loadRequest:request];
[self.view addSubview:webView];
}else{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"nil" message:@"对不起,您还没安装QQ" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
return ;
}];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
注意:如果你的QQ不是客服QQ会出现红色的感叹号如下:

想要解决也很简单打开QQ推广设置一下就可以了
1.打开http://shang.qq.com/v3/index.html 点击推广工具------> 点击立即免费开通

2.点击QQ通讯组件------>选择标准型组件样式 点击设置

3.设置自动回复 和 会话能力

4.向下滚动设置权限和安全级别

设置完之后大家再试一下 是不是就可以正常聊天了那
网友评论
//在这里放QQ号
NSString *qqNumber = @"2158015525";
NSString *openQQUrl = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqNumber];
NSURL *url = [NSURL URLWithString:openQQUrl];
[[UIApplication sharedApplication] openURL:url];
//在这里放QQ号
NSString *qqNumber = @"2158015525";
NSString *openQQUrl = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqNumber];
NSURL *url = [NSURL URLWithString:openQQUrl];
[[UIApplication sharedApplication] openURL:url];
//在这里放QQ号
NSString *qqNumber = @"2158015525";
NSString *openQQUrl = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqNumber];
NSURL *url = [NSURL URLWithString:openQQUrl];
[[UIApplication sharedApplication] openURL:url];