iOS开发之第三方分享QQ分享实现
2016-09-12 13:19
429 查看
分享第三方分享之QQ分享各种坑的总结:
1. 分享老是提示未注册QQ,解决办法就是在程序已启动,就向QQ进行授权。代码如下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[TencentOAuth alloc] initWithAppId:TENCENT_CONNECT_APP_KEY andDelegate:self];
return YES;
}
QQ未注册错误代号EQQAPIAPPNOTREGISTED
2. 分享的时候, 不跳转到QQ界面,解决办法就是在openurl中,添加如下代码:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{
if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {
[QQApiInterface handleOpenURL:url delegate:self];
return [TencentOAuth HandleOpenURL:url];
}
return YES;
}
3. iOS9白名单的问题,没有吧QQ的相关白名单填完成。 完成的如下。
LSApplicationQueriesSchemes
mqqapi
mqq
mqqOpensdkSSoLogin
mqqconnect
mqqopensdkdataline
mqqopensdkgrouptribeshare
mqqopensdkfriend
mqqopensdkapi
mqqopensdkapiV2
mqqopensdkapiV3
mqzoneopensdk
wtloginmqq
wtloginmqq2
mqqwpa
mqzone
mqzonev2
mqzoneshare
wtloginqzone
mqzonewx
mqzoneopensdkapiV2
mqzoneopensdkapi19
mqzoneopensdkapi
mqzoneopensdk
进入正题:
分享的对象包含:
QQApiTextObject 文本对象
QQApiURLObject URL对象类型
QQApiExtendObject 扩展数据类型
QQApiImageObject 图片对象
QQApiImageArrayForQZoneObject 图片数组对象用于分享图片到空间,走写说说路径,是一个指定为图片类型的,当图片数组为空时,默认走文本写说说
QQApiVideoForQZoneObject 视频对象
QQApiWebImageObject 网络图片对象
QQApiFileObject 本地文件对象
QQApiAudioObject 音频URL对象
QQApiVideoObject 视频URL对象:用于分享目标内容为视频的URL的对象
QQApiNewsObject 新闻URL对象
等等。
相关的分享对象的权限看下图:
分享的核心代码为: (分享 新闻URL对象为例子)
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"]
previewImageURL:preimageUrl];
//请求帮助类,分享的所有基础对象,都要封装成这种请求对象。
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//通过自定义的qqdelegate来通知本controller,是否成功分享
appdelegate.qqDelegate = self;
NSLog(@"QQApiSendResultCode %d",sent);
[self handleSendResult:sent];
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
switch (sendResult)
{
case EQQAPIAPPNOTREGISTED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIMESSAGECONTENTINVALID:
case EQQAPIMESSAGECONTENTNULL:
case EQQAPIMESSAGETYPEINVALID:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTINSTALLED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTSUPPORTAPI:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPISENDFAILD:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIVERSIONNEEDUPDATE:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
default:
{
break;
}
}
}
上面提到了分享。那么如何来监听分享是否成功呢。这就要回到我们的appdelegate里面。监听
- (void)onResp:(QQBaseResp *)resp
appdelegate中的相关代码如下:
**
处理来至QQ的响应
*/
- (void)onResp:(QQBaseResp *)resp{
NSLog(@" ----resp %@",resp);
// SendMessageToQQResp应答帮助类
if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) { //QQ分享回应
if (_qqDelegate) {
if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;
NSLog(@"code %@ errorDescription %@ infoType %@",resp.result,resp.errorDescription,resp.extendInfo);
[_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];
}
}
}
}
分享的核心代码为: (分享 新闻URL对象为例子)
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"]
previewImageURL:preimageUrl];
//请求帮助类,分享的所有基础对象,都要封装成这种请求对象。
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//通过自定义的qqdelegate来通知本controller,是否成功分享
appdelegate.qqDelegate = self;
NSLog(@"QQApiSendResultCode %d",sent);
[self handleSendResult:sent];
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
switch (sendResult)
{
case EQQAPIAPPNOTREGISTED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIMESSAGECONTENTINVALID:
case EQQAPIMESSAGECONTENTNULL:
case EQQAPIMESSAGETYPEINVALID:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTINSTALLED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTSUPPORTAPI:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPISENDFAILD:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIVERSIONNEEDUPDATE:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
default:
{
break;
}
}
}
上面提到了分享。那么如何来监听分享是否成功呢。这就要回到我们的appdelegate里面。监听
- (void)onResp:(QQBaseResp *)resp
appdelegate中的相关代码如下:
**
处理来至QQ的响应
*/
- (void)onResp:(QQBaseResp *)resp{
NSLog(@" ----resp %@",resp);
// SendMessageToQQResp应答帮助类
if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) { //QQ分享回应
if (_qqDelegate) {
if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;
NSLog(@"code %@ errorDescription %@ infoType %@",resp.result,resp.errorDescription,resp.extendInfo);
[_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];
}
}
}
}
1. 分享老是提示未注册QQ,解决办法就是在程序已启动,就向QQ进行授权。代码如下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[TencentOAuth alloc] initWithAppId:TENCENT_CONNECT_APP_KEY andDelegate:self];
return YES;
}
QQ未注册错误代号EQQAPIAPPNOTREGISTED
2. 分享的时候, 不跳转到QQ界面,解决办法就是在openurl中,添加如下代码:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{
if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {
[QQApiInterface handleOpenURL:url delegate:self];
return [TencentOAuth HandleOpenURL:url];
}
return YES;
}
3. iOS9白名单的问题,没有吧QQ的相关白名单填完成。 完成的如下。
LSApplicationQueriesSchemes
mqqapi
mqq
mqqOpensdkSSoLogin
mqqconnect
mqqopensdkdataline
mqqopensdkgrouptribeshare
mqqopensdkfriend
mqqopensdkapi
mqqopensdkapiV2
mqqopensdkapiV3
mqzoneopensdk
wtloginmqq
wtloginmqq2
mqqwpa
mqzone
mqzonev2
mqzoneshare
wtloginqzone
mqzonewx
mqzoneopensdkapiV2
mqzoneopensdkapi19
mqzoneopensdkapi
mqzoneopensdk
进入正题:
分享的对象包含:
QQApiTextObject 文本对象
QQApiURLObject URL对象类型
QQApiExtendObject 扩展数据类型
QQApiImageObject 图片对象
QQApiImageArrayForQZoneObject 图片数组对象用于分享图片到空间,走写说说路径,是一个指定为图片类型的,当图片数组为空时,默认走文本写说说
QQApiVideoForQZoneObject 视频对象
QQApiWebImageObject 网络图片对象
QQApiFileObject 本地文件对象
QQApiAudioObject 音频URL对象
QQApiVideoObject 视频URL对象:用于分享目标内容为视频的URL的对象
QQApiNewsObject 新闻URL对象
等等。
相关的分享对象的权限看下图:
分享的核心代码为: (分享 新闻URL对象为例子)
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"]
previewImageURL:preimageUrl];
//请求帮助类,分享的所有基础对象,都要封装成这种请求对象。
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//通过自定义的qqdelegate来通知本controller,是否成功分享
appdelegate.qqDelegate = self;
NSLog(@"QQApiSendResultCode %d",sent);
[self handleSendResult:sent];
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
switch (sendResult)
{
case EQQAPIAPPNOTREGISTED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIMESSAGECONTENTINVALID:
case EQQAPIMESSAGECONTENTNULL:
case EQQAPIMESSAGETYPEINVALID:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTINSTALLED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTSUPPORTAPI:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPISENDFAILD:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIVERSIONNEEDUPDATE:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
default:
{
break;
}
}
}
上面提到了分享。那么如何来监听分享是否成功呢。这就要回到我们的appdelegate里面。监听
- (void)onResp:(QQBaseResp *)resp
appdelegate中的相关代码如下:
**
处理来至QQ的响应
*/
- (void)onResp:(QQBaseResp *)resp{
NSLog(@" ----resp %@",resp);
// SendMessageToQQResp应答帮助类
if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) { //QQ分享回应
if (_qqDelegate) {
if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;
NSLog(@"code %@ errorDescription %@ infoType %@",resp.result,resp.errorDescription,resp.extendInfo);
[_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];
}
}
}
}
分享的核心代码为: (分享 新闻URL对象为例子)
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"]
previewImageURL:preimageUrl];
//请求帮助类,分享的所有基础对象,都要封装成这种请求对象。
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//通过自定义的qqdelegate来通知本controller,是否成功分享
appdelegate.qqDelegate = self;
NSLog(@"QQApiSendResultCode %d",sent);
[self handleSendResult:sent];
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
switch (sendResult)
{
case EQQAPIAPPNOTREGISTED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIMESSAGECONTENTINVALID:
case EQQAPIMESSAGECONTENTNULL:
case EQQAPIMESSAGETYPEINVALID:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTINSTALLED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTSUPPORTAPI:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPISENDFAILD:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消"
otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIVERSIONNEEDUPDATE:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
default:
{
break;
}
}
}
上面提到了分享。那么如何来监听分享是否成功呢。这就要回到我们的appdelegate里面。监听
- (void)onResp:(QQBaseResp *)resp
appdelegate中的相关代码如下:
**
处理来至QQ的响应
*/
- (void)onResp:(QQBaseResp *)resp{
NSLog(@" ----resp %@",resp);
// SendMessageToQQResp应答帮助类
if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) { //QQ分享回应
if (_qqDelegate) {
if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;
NSLog(@"code %@ errorDescription %@ infoType %@",resp.result,resp.errorDescription,resp.extendInfo);
[_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];
}
}
}
}
相关文章推荐
- iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现
- iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现
- iOS开发中 实现登录时关于使用QQ做为第三方授权登录的问题
- iOS开发之第三方登录QQ -- 史上最全最新第三方登录QQ方式实现
- 实现QQ的第三方登录 iOS开发
- iOS开发之第三方登录QQ -- 史上最全最新第三方登录QQ方式实现
- iOS开发之第三方分享微信分享、朋友圈分享,史上最新最全第三方分享微信方式实现、朋友圈方式实现
- iOS开发 实现QQ第三方登录
- iOS开发之第三方分享微博分享、微博分享失败原因总结,史上最新最全第三方分享微博方式实现。 微博分享各种坑总结
- iOS开发之第三方登录QQ -- 史上最全最新第三方登录QQ方式实现
- iOS开发 ios9.0后友盟第三方分享, qq微信找不到设备
- iOS开发---集成ShareSDK实现第三方登录、分享、关注等功能。
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- iOS集成QQ、微信、微博、短信、邮件分享(非第三方集成)
- iOS开发-仿微信图片分享界面实现
- ios第三方分享到qq、微信、人人网、微博总结
- ios开发——仿新版QQ侧滑导航栏的实现
- iOS开发-仿微信图片分享界面实现
- ios第三方分享到qq、微信、人人网、微博总结
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。