无需友盟直接在官网集成就行
步骤
1.上官网地址下载 QQ的 SDK 此处给大家一个链接其中包括微博, 微信,朋友圈,人人等的地址
2.将文件导入工程两个东西
3.环境搭建第三方登录等等下载环境搭建的 Word 写的非常清楚
4.此前应该申请好 appkey然后在工程中开始注册上代码
self.tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"" andDelegate:self];
self.tencentOAuth.redirectURI = @"";
这个地方还有一个链接,delegate 的地方最好填东西,可能需要第三方登陆.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [TencentOAuth HandleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [TencentOAuth HandleOpenURL:url];
}
5.发送消息类型(sharevo 是我写的一个对象,它的作用就是传值, sharevo 中有很多属性(title des image 是 nsdata 类型的 link 即是网址等等))
#pragma mark - QQ 和 QQ空间
// 发送内容(文本,图片,链接)
- (void) sendTextMessage:(ShareVO *)share
{
QQApiTextObject* txtObj = [QQApiTextObject objectWithText:share.title];
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:txtObj];
//qq
QQApiSendResultCode sentQ = [QQApiInterface sendReq:req];
[self handleSendResult:sentQ];
//qq空间
//QQApiSendResultCode sentQZone = [QQApiInterface SendReqToQZone:req];
//[self handleSendResult:sentQZone];
}
- (void) sendImageMessage:(ShareVO *)share
{
QQApiImageObject* img = [QQApiImageObject objectWithData:share.image previewImageData:share.image title:share.title description:share.des];
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
//qq
QQApiSendResultCode sentQ = [QQApiInterface sendReq:req];
[self handleSendResult:sentQ];
//qq空间
//QQApiSendResultCode sentQZone = [QQApiInterface SendReqToQZone:req];
//[self handleSendResult:sentQZone];
}
- (void) sendNewsMessageWithLocalImage:(ShareVO *)share
{
NSURL* url = [NSURL URLWithString:share.link];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:share.title description:share.des previewImageData:share.image];
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
//qq
QQApiSendResultCode sentQ = [QQApiInterface sendReq:req];
[self handleSendResult:sentQ];
//qq空间
//QQApiSendResultCode sentQZone = [QQApiInterface SendReqToQZone:req];
//[self handleSendResult:sentQZone];
}
//音乐
- (void)sendMusicMessage:(ShareVO *)share {
//分享跳转URL
NSString *url = @"http://xxx.xxx.xxx/";
//分享图预览图URL地址
NSString *previewImageUrl = @"preImageUrl.png";
//音乐播放的网络流媒体地址
NSString *flashURL = @"xxx.mp3 ";
QQApiAudioObject *audioObj =[QQApiAudioObject
objectWithURL :[NSURL URLWithString:url]
title:@"title"
description:@"description"
previewImageURL:[NSURL URLWithString:previewImageUrl]];
//设置播放流媒体地址
[audioObj setFlashURL:[NSURL URLWithString:flashURL]];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:audioObj];
//qq
QQApiSendResultCode sentQ = [QQApiInterface sendReq:req];
[self handleSendResult:sentQ];
//qq空间
//QQApiSendResultCode sentQZone = [QQApiInterface SendReqToQZone:req];
//[self handleSendResult:sentQZone];
}
//返回错误方法
- (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;
}
}
}
注意
有些类是不支持分享到空间的