根据 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];
}
网友评论