美文网首页
iOS 同时集成微信QQ 登陆和分享

iOS 同时集成微信QQ 登陆和分享

作者: 慧煎蛋 | 来源:发表于2018-09-18 16:45 被阅读0次

主要自己遇到以下两个问题

1.QQ登陆不走回调代理方法 tencentDidLogin

2.处理QQ分享和微信分享走同名方法 onResp

记录一下, 给自己提个醒

ps. 在unity项目中实现调起微信等第三方实现登陆分享支付

首先遵循代理

< WXApiDelegate, TencentSessionDelegate, QQApiInterfaceDelegate>

@property (nonatomic, strong) TencentOAuth *tencentOAuth;

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    [WXApi registerApp: @"wx9c95cb8805f8a"];
    _tencentOAuth = [[TencentOAuth alloc] initWithAppId:@"222222" andDelegate:self];
    return YES;
}

appDelegate里实现

-(BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary *)options
{//for iOS10 or more
    NSLog(@"%@", _tencentOAuth);

    [WXApi handleOpenURL:url delegate:self];//微信登陆和分享回调url处理
    [QQApiInterface handleOpenURL:url delegate:self];//QQ分享回调url处理 
    [TencentOAuth HandleOpenURL:url];//!!!如果不写, 不走QQ登陆回调代理方法
    return true;
}

-(BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{//for iOS9 or older
    [WXApi handleOpenURL:url delegate:self];
    [QQApiInterface handleOpenURL:url delegate:self];
    [TencentOAuth HandleOpenURL:url];
    return true;
}

OnResp 微信 登陆 支付 分享 的回调, QQ分享的回调

- (void)onResp:(BaseResp*)resp
{
    if([respisKindOfClass:[SendAuthRespclass]])
    {
        SendAuthResp*resp1 = (SendAuthResp*)resp;
        NSLog(@"WX登陆: %d", resp1.errCode);
        if(resp1.errCode==0) {
            NSLog(@"WX登陆suc: %@", resp1.code);
            UnitySendMessage("_Wx_Call", "LoginCallBack", [resp1.code cStringUsingEncoding:NSUTF8StringEncoding]);
        }else{
            UnitySendMessage("_Wx_Call", "LoginCallBack", "fail");
        }
    }

    if([respisKindOfClass:[PayRespclass]])
    {
        PayResp*resp1 = (PayResp*)resp;
        NSLog(@"WXpay: %d", resp1.errCode);
        if(resp1.errCode==0) {
            UnitySendMessage("_Wx_Call", "PayCallBack", "success");
        }else{
            UnitySendMessage("_Wx_Call", "PayCallBack", "fail");
        }
    }

    if ([resp isKindOfClass:[SendMessageToWXResp class]])
    {// 分享// 0是成功 -2是取消
        SendMessageToWXResp *resp1 = (SendMessageToWXResp *)resp;
        NSLog(@"WX分享: %d", resp1.errCode);
        if(resp1.errCode==0) {
            UnitySendMessage("_Wx_Call", "ShareCallBack", "success");
        }else{
            UnitySendMessage("_Wx_Call", "ShareCallBack", "fail");
        }
    }

    if ([resp isKindOfClass:[SendMessageToQQResp class]])
    {// 分享// 0是成功 -4是取消
        SendMessageToQQResp *resp1 = (SendMessageToQQResp *)resp;
        NSLog(@"QQ分享: %@", resp1.result);
        if(resp1.type==ESENDMESSAGETOQQRESPTYPE&& [resp1.resultintegerValue] ==0) {
            UnitySendMessage("_Wx_Call", "ShareCallBack", "success");
        }else{
            UnitySendMessage("_Wx_Call", "ShareCallBack", "fail");
        }
    }
}

QQ登陆和其回调

- (void)QQLoginDo
{//QQ登陆方法 可以使用通知来调用
    NSArray *permissions = [NSArray arrayWithObjects:kOPEN_PERMISSION_GET_INFO, kOPEN_PERMISSION_GET_USER_INFO, kOPEN_PERMISSION_GET_SIMPLE_USER_INFO, nil];
    [_tencentOAuthauthorize:permissionsinSafari:NO];
}

- (void)tencentDidLogin
{
    if (_tencentOAuth.accessToken.length > 0) {
        [_tencentOAuth getUserInfo];
        NSLog(@"qq登陆 %@", _tencentOAuth.accessToken);
        UnitySendMessage("_QQ_Call", "LoginCallBack", [_tencentOAuth.accessToken cStringUsingEncoding:NSUTF8StringEncoding]);
    }else{
        UnitySendMessage("_QQ_Call", "LoginCallBack", "fail");
    }
}

- (void)tencentDidNotLogin:(BOOL)cancelled {
    UnitySendMessage("_QQ_Call", "LoginCallBack", "fail");
}

相关文章

网友评论

      本文标题:iOS 同时集成微信QQ 登陆和分享

      本文链接:https://www.haomeiwen.com/subject/ddipnftx.html