iOS 跳转QQ客服踩坑

根据 QQ SDK,进入临时会话,跳转后理所当然的发送消息失败了。详细代码如下:

QQApiWPAObject *wpaObj = [QQApiWPAObject objectWithUin:@"4008205555"];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:wpaObj];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
if (sent == EQQAPIQQNOTINSTALLED || sent == EQQAPIQQNOTSUPPORTAPI) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 提示 " message:@" 请先安装 QQ" delegate:nil cancelButtonTitle:@" 确定 " otherButtonTitles:nil, nil];
    [alert show];
}

用协议的方式,在通用的WebViewController中:

NSString *url = @"mqqwpa://im/chat?chat_type=crm&uin=4008205555&version=1&src_type=web&web_src=http:://wpa.b.qq.com";  
NSURL *qqURL = [NSURL URLWithString:url];  
[self.webView loadRequest:[NSURLRequest requestWithURL:qqURL]];  

在网页中跳转可以由服务端直接返回上述 URL。由于原生、网页中都可能会跳转,用上述方法不好确定用户是否安装了QQ,还是在本地统一处理比较好:

NSString *url = @"mqqwpa://im/chat?chat_type=crm&uin=4008205555&version=1&src_type=web&web_src=http:://wpa.b.qq.com";  
NSURL *qqURL = [NSURL URLWithString:url];
BOOL hasInstalled = [[UIApplication sharedApplication] canOpenURL:qqURL];

if (!hasInstalled) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 提示 " message:@" 请先安装 QQ" delegate:nil cancelButtonTitle:@" 确定 " otherButtonTitles:nil, nil];
    [alert show];
} else {
    [[UIApplication sharedApplication] openURL:qqURL];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,165评论 25 709
  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 14,766评论 0 15
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,084评论 19 139
  • 日前,路过沈阳,恰巧有四个小时逗留时间。早闻知沈阳故宫很有名气,便在沈阳站约车前往。匆匆一览,深有感慨。 ...
    宏波_阅读 1,454评论 0 1
  • 抓一把风 绕指尖,一丝丝剥离 撒进风里 吹一支凌乱的笛 拣出凌乱 梳理调皮的曲 一叶随风起 起如骄阳 一叶随风落 ...
    suisuidaoren阅读 2,795评论 0 0

友情链接更多精彩内容