根據(jù) QQ SDK,進(jìn)入臨時會話,跳轉(zhuǎn)后理所當(dāng)然的發(fā)送消息失敗了。詳細(xì)代碼如下:
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];
}
用協(xié)議的方式,在通用的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]];
在網(wǎng)頁中跳轉(zhuǎn)可以由服務(wù)端直接返回上述 URL。由于原生、網(wǎng)頁中都可能會跳轉(zhuǎn),用上述方法不好確定用戶是否安裝了QQ,還是在本地統(tǒng)一處理比較好:
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];
}