iOS - 基于 ShareSDK 的QQ授权登录开发记录

这篇博客记录了如何在iOS应用中使用ShareSDK进行QQ授权登录的开发过程,包括获取ShareSDK的Key和设置QQ登录权限的详细步骤。
摘要由CSDN通过智能技术生成

获得ShareSDK的Key,并获得QQ授权登录功能权限

参考 http://wiki.mob.com/快速集成指南/

代码

//
//  rootViewController.m
//  leaf
//
//  Created by command.Zi on 14/12/3.
//  Copyright (c) 2014年 command.Zi. All rights reserved.
//

#import "XYZsecondViewController.h"
#import <Parse/Parse.h>
#import <ShareSDK/ShareSDK.h>

@interface XYZsecondViewController ()
- (IBAction)login:(id)sender;
- (IBAction)logout:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *idLabel;
@property (strong, nonatomic) IBOutlet UIImageView *Logimage;

@end

@implementation XYZsecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)login:(id)sender {
    [ShareSDK getUserInfoWithType:ShareTypeQQSpace //类型为QQ空间,非QQ
                      authOptions:nil
                           result:^(BOOL result, id<ISSPlatformUser> userInfo, id<ICMErrorInfo> error) {
                               if (result)
                               {
                                   PFQuery *query = [PFQuery queryWithClassName:@"UserInfo"];
                                   [query whereKey:@"uid" equalTo:[userInfo uid]];
                                   [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                                       if ([objects count] == 0)
                                       {
                                           //打印输出用户uid:
                                           NSLog(@"uid = %@",[userInfo uid]);
                                           //打印输出用户昵称:
                                           NSLog(@"name = %@",[userInfo nickname]);
                                           //打印输出用户头像地址:
                                           NSLog(@"icon = %@",[userInfo profileImage]);
                                           PFObject *newUser = [PFObject objectWithClassName:@"UserInfo"];
                                           [newUser setObject:[userInfo uid] forKey:@"uid"];
                                           [newUser setObject:[userInfo nickname] forKey:@"name"];
                                           [newUser setObject:[userInfo profileImage] forKey:@"icon"];
                                           [newUser saveInBackground];
                                           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"欢迎注册" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles: nil];
                                           [alertView show];
//                                           showLabelimage:(NSString *)name logid:(NSString *)logid logimg:(UIImage *)imgurl
                                           
                                           [self showLabelimage:[userInfo nickname] logid:[userInfo uid] logimgstr:[userInfo profileImage]];
                                       }
                                       else
                                       {
                                           //打印输出用户uid:
                                           NSLog(@"uid = %@",[userInfo uid]);
                                           //打印输出用户昵称:
                                           NSLog(@"name = %@",[userInfo nickname]);
                                           //打印输出用户头像地址:
                                           NSLog(@"icon = %@",[userInfo profileImage]);
                                           NSLog(@"AAAAA = %@",userInfo);
                                           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"欢迎回来" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles: nil];
                                           [alertView show];
                                           [self showLabelimage:[userInfo nickname] logid:[userInfo uid] logimgstr:[userInfo profileImage]];
                                       }
                                   }];
//                                   MainViewController *mainVC = [[[MainViewController alloc] init] autorelease];
//                                   [self.navigationController pushViewController:mainVC animated:YES];
                               }
                           }];
}

//注销
- (IBAction)logout:(id)sender {
    [ShareSDK cancelAuthWithType:ShareTypeQQSpace];
    [self showLabelimage:nil logid:nil logimgstr:nil];
}

//setlabel
-(void)showLabelimage:(NSString *)name logid:(NSString *)logid logimgstr:(NSString *)imgurl {
    UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]];
    self.nameLabel.text = name;
    self.idLabel.text = logid;
    self.Logimage.image = img;
}

@end


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值