msgbox.html5.qq.com,QQ原生第三方登录 分享接入

1,首页需要去腾讯开发者平台注册应用  并且审核通过  获取appid

2,pod 'TencentOpenAPI-Unofficial', '~> 3.3.0'

#import

#import

在xcode  URLtype  加入tencent这个是appid  identifier :com.tencent

记得加入白名单

LSApplicationQueriesSchemes

wechat

weixin

sinaweibohd

sinaweibo

sinaweibosso

weibosdk

weibosdk2.5

mqqapi

mqq

mqqOpensdkSSoLogin

mqqconnect

mqqopensdkdataline

mqqopensdkgrouptribeshare

mqqopensdkfriend

mqqopensdkapi

mqqopensdkapiV2

mqqopensdkapiV3

mqqopensdkapiV4

mqzoneopensdk

wtloginmqq

wtloginmqq2

mqqwpa

mqzone

mqzonev2

mqzoneshare

wtloginqzone

mqzonewx

mqzoneopensdkapiV2

mqzoneopensdkapi19

mqzoneopensdkapi

mqqbrowser

mttbrowser

在appdelegate  回调

@property (nonatomic,strong) TencentOAuth *oauth;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

{

//注意: 初始化授权 开发者需要在这里填入自己申请到的 AppID

_oauth = [[TencentOAuth alloc] initWithAppId:QQ_Appid andDelegate:self];

}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{

[TencentOAuth HandleOpenURL:url];

return YES;

}

然后在第三方登录界面

- (void)getAuthWithUserInfoFromQQ{

self.tencentOAuth = [[TencentOAuth alloc]initWithAppId:@"appid" andDelegate:self];

NSMutableArray *permission = [@[] mutableCopy];    permission = [NSMutableArray arrayWithObjects:@"get_user_info",@"get_simple_userinfo",nil];    [self.tencentOAuth authorize:permission inSafari:NO];

}

#pragma mark --------- qq登录状态回调  TencentSessionDelegate------

- (void)tencentDidNotNetWork{

NSLog(@"没有网络,无法登录");

}

- (void)tencentDidLogin{

if (_tencentOAuth.accessToken){

NSLog(@"%@ == %@",_tencentOAuth.accessToken,_tencentOAuth.openId);

[self.tencentOAuth getUserInfo];

}else{

NSLog(@"登录失败!没有获取到accessToken");

}

}

/** * 登录失败后的回调 */

- (void)tencentDidNotLogin:(BOOL)cancelled{

if (cancelled){

NSLog(@"用户取消登录");

}else{

NSLog(@"登录失败");

}

}

- (void)getUserInfoResponse:(APIResponse *)response

{

NSLog(@"%@",response.jsonResponse);

}

分享

QQApiTextObject *txtObj = [QQApiTextObject objectWithText:@"share text"];

SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:txtObj];

dispatch_async(dispatch_get_main_queue(), ^{

//                [QQApiInterface SendReqToQZone:req];

QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];//分享到QQ空间

[self handleSendResult:sent];

qq好友

QQApiTextObject *txtObj = [QQApiTextObject objectWithText:@"share text"];

SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:txtObj];

dispatch_async(dispatch_get_main_queue(), ^{

//                [QQApiInterface sendReq:req];

QQApiSendResultCode sent = [QQApiInterface sendReq:req];//分享到QQ空间

[self handleSendResult:sent];

});

- (void)handleSendResult:(QQApiSendResultCode)sendResult

{

switch (sendResult)

{

case EQQAPIAPPNOTREGISTED:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

case EQQAPIMESSAGECONTENTINVALID:

case EQQAPIMESSAGECONTENTNULL:

case EQQAPIMESSAGETYPEINVALID:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

case EQQAPIQQNOTINSTALLED:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

case EQQAPIQQNOTSUPPORTAPI:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您的设备未安装手机QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

case EQQAPISENDFAILD:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

case EQQAPIVERSIONNEEDUPDATE:

{

UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前QQ版本太低,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];

[msgbox show];

break;

}

default:

{

break;

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值