ShareSDK第三方登录代码

- (IBAction)YYSJBut:(UIButton *)sender
{
    if (sender.tag == 7)
    {
        [self AuthLogin:SSDKPlatformTypeSinaWeibo];
    }else if (sender.tag == 8)
    {
        [self AuthLogin:SSDKPlatformTypeWechat];
    }else
    {
        [self AuthLogin:SSDKPlatformTypeQQ];
    }
}

-(void)AuthLogin:(SSDKPlatformType)type
{
    DefineWeakSelf;
    [SSEThirdPartyLoginHelper loginByPlatform:type
                                   onUserSync:^(SSDKUser *user, SSEUserAssociateHandler associateHandler)
    {
        associateHandler(user.uid,user,user);
        [[AFSmsBlock smsBlock]AuthLogin:user.credential.token
                                   path:user.icon
                                    sex:user.gender
                               nickname:user.nickname
                                open_id:user.uid
                         registrationid:[DEFAULTS valueForKey:@"RegistrationID"]
                           successBlock:^(id jsonStr)
        {
            [weakSelf SuccessLogin:jsonStr];
        }];
    } onLoginResult:^(SSDKResponseState state, SSEBaseUser *user, NSError *error)
    {
        if (state == SSDKResponseStateSuccess)
        {
            NSLog(@" %@ **** %@ ",user.linkId,user.socialUsers);
        }
    }];
}




-(void)SuccessLogin:(id)jsonStr
{
if ([jsonStr[@"status"][@"succeed"]intValue] == 1)
    {
        [DEFAULTS setObject:jsonStr[@"status"][@"succeed"] forKey:@"status"];
        [DEFAULTS setObject:jsonStr[@"data"][@"uid"] forKey:@"uid"];
        [DEFAULTS setObject:jsonStr[@"data"][@"nickname"] forKey:@"nickname"];
        [AFUser_Model UserLogin:jsonStr[@"data"]];
        [self.navigationController popViewControllerAnimated:YES];
    }else
    {
        [AFHCProgressHub showErrorWithStatus:jsonStr[@"status"][@"error_desc"]];
    }
}

posted @ 2016-08-26 09:37  Jack~Bai  阅读(460)  评论(0编辑  收藏  举报