0、先说现象:找开App在使用QQ分享时提示“参数错误”,第一次分享时都会这样,重复操作一切正常!
1、正常情况下项目中使用QQ分享功能,只需要创建分享对象,然后调用接口分享即可,官方代码示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| NSString *utf8String = @"http://www.163.com";
NSString *title = @"新闻标题";
NSString *description = @"新闻描述";
NSString *previewImageUrl = @"http://cdni.wired.co.uk/620x413/k_n/NewsForecast%20copy_620x413.jpg";
QQApiNewsObject *newsObj = [QQApiNewsObject
objectWithURL:[NSURL URLWithString:utf8String]
title:title
description:description
previewImageURL:[NSURL URLWithString:previewImageUrl]];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
//将内容分享到qq
//QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//将内容分享到qzone
QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req]; |
NSString *utf8String = @"http://www.163.com";
NSString *title = @"新闻标题";
NSString *description = @"新闻描述";
NSString *previewImageUrl = @"http://cdni.wired.co.uk/620x413/k_n/NewsForecast%20copy_620x413.jpg";
QQApiNewsObject *newsObj = [QQApiNewsObject
objectWithURL:[NSURL URLWithString:utf8String]
title:title
description:description
previewImageURL:[NSURL URLWithString:previewImageUrl]];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
//将内容分享到qq
//QQApiSendResultCode sent = [QQApiInterface sendReq:req];
//将内容分享到qzone
QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
2、然而官方没有提醒你,在此之前必须先将TencentOAuth对象实例化,即必须先执行以下代码:
1
| self.oauth = [[TencentOAuth alloc] initWithAppId:kSAAppID_QQ andDelegate:self]; |
self.oauth = [[TencentOAuth alloc] initWithAppId:kSAAppID_QQ andDelegate:self];
3、理论上有这些就足够了,但事实并非如此,比如说官方的Demo在分享时控制台会有一个logo输出[……]
继续阅读