iOS 打开 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会出现红色的感叹号如下:
![](http://upload-images.jianshu.io/upload_images/1433429-4c0eb50fc64be45e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
解决方案 打开QQ推进行设置一下就可以了
具体步骤如下:
1.打开http://shang.qq.com/v3/index.html 点击推广工具------> 点击立即免费开通
![](http://upload-images.jianshu.io/upload_images/1433429-ec65f2d895366e48.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2.点击QQ通讯组件------>选择标准型组件样式 点击设置
![](http://upload-images.jianshu.io/upload_images/1433429-3a75065bdd19d90f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.设置自动回复 和 会话能力
![](http://upload-images.jianshu.io/upload_images/1433429-71ffc07b6e9e3395.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4.向下滚动设置权限和安全级别
![](http://upload-images.jianshu.io/upload_images/1433429-b8d749a73694fe0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
设置完之后大家再试一下 就可以正常接收陌生人聊天了
文/红姑娘(简书作者)
原文链接:http://www.jianshu.com/p/d306a443bcc8
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
原文链接:http://www.jianshu.com/p/d306a443bcc8
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。