• QQ简单登录


    1.下载QQ官方API文档,导入对应的包

    2.在Info->URL Types文件添加

    Identifier:tencent  URL Schemes:tencent+应用appkey(去腾讯后台注册)

    3.Appdelegate文件

    #pragma mark --- QQLogin-----
    - (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];
    }

    4.对应的viewController文件

    #import <TencentOpenAPI/TencentOAuth.h>
    
    @interface LoginController ()<TencentSessionDelegate>
    {
        UIView *_loginView;
        TencentOAuth *_tencentLogin;
    }
    //QQ
    -(void)qqLogin:(UIButton *)btn
    {
        _tencentLogin=[[TencentOAuth alloc]initWithAppId:@"222222" andDelegate:self];
         NSArray *permissions = [NSArray arrayWithObjects:@"get_user_info", @"get_simple_userinfo", @"add_t", nil];
        [_tencentLogin authorize:permissions localAppId:@"222222" inSafari:YES];
    }
    
    #pragma mark----QQLogin----
    -(void)tencentDidLogin
    {
        NSString *infoUrl=[NSString stringWithFormat:@"https://graph.qq.com/user/get_simple_userinfo?access_token=%@&oauth_consumer_key=%@&openid=%@",_tencentLogin.accessToken,@"222222",_tencentLogin.openId];
        //NSLog(@"%@",infoUrl);
        [NetWorkManage getUserInfoByQQWithUrl:infoUrl whenSuccess:^(id responseData) {
            id result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:nil];
            if ([result isKindOfClass:[NSDictionary class]]) {
                NSDictionary *userDic = result;
                //
                NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
                NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:userDic[@"figureurl_qq_2"]]];
                [userDefault setObject:userDic[@"nickname"] forKey:@"NickName"];
                [userDefault setObject:data forKey:@"UserImg"];
                [userDefault synchronize];
                self.showUserData();
                [self.navigationController popViewControllerAnimated:YES];
            }
        } Failure:^(NSError *error) {
            
        }];
    }
    -(void)tencentDidNotNetWork
    {
        
    }
    -(void)tencentDidNotLogin:(BOOL)cancelled
    {
        
    }
  • 相关阅读:
    CSS——实现图像远距离翻转效果
    《精通CSS》一个下拉菜单的例子
    将博客搬至CSDN
    44个Java代码性能优化总结
    QRCode 二维码生成
    Linux命令
    spring
    ajax 学习总结
    Servlet+Ajax实现搜索框智能提示代码
    搜索框智能提示
  • 原文地址:https://www.cnblogs.com/liaods/p/4805369.html
Copyright © 2020-2023  润新知