新浪微博登录SDK

导入libsqlite3.tbd-----adSupport.framework------ImageIO.framework---JAVAScriptCore.framework

libstdc++.tbd---------libz.tbd----libicucore.tbd

//新浪微博SDK需要在项目Build Settings中的Other Linker Flags添加"-ObjC"


新版本在Infor.plist  中添加App transport.....中添加Allow...把后面的NO改为YES 

将SDK导入

Appdelegate  导入头文件

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

#import "WeiboSDK.h"

#import "ViewController.h"


   // Override point for customization after application launch.

    ViewController *vc = [[ViewController alloc]init];

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];

    self.window.rootViewController = nav;

    

    [ShareSDK registerApp:@"iosv1101"

     

          activePlatforms:@[@(SSDKPlatformTypeSinaWeibo)]

                 onImport:^(SSDKPlatformType platformType)

     {

         switch (platformType)

         {

            case SSDKPlatformTypeSinaWeibo:

                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];

                 break;

            

             default:

                 break;

         }

     }

          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)

     {

         

         switch (platformType)

         {

             case SSDKPlatformTypeSinaWeibo:

                 //设置新浪微博应用信息,其中authType设置为使用SSOWeb形式授权

                 [appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"

                                           appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"

                                         redirectUri:@"http://www.sharesdk.cn"

                                            authType:SSDKAuthTypeBoth];

                 break;

          

             default:

                 break;

         }

     }];


在ViewControllers.m中加入头文件

#import "WeiboSDK.h"

#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>


@interface ViewController ()

{

    UILabel *lab;

    UILabel *lab1;

    UILabel *lab2;

    UILabel *labname;

    UILabel *labfan;

    UILabel *labfriend;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    self.navigationItem.title = @"新浪微博登陆";

    self.view.backgroundColor = [UIColor whiteColor];

    

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [btn setTitle:@"新浪微博登陆" forState:UIControlStateNormal];

    btn.frame = CGRectMake(100, 200, 100, 30);

    [self.view addSubview:btn];

    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

    

    

    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [btn1 setTitle:@"退出" forState:UIControlStateNormal];

    btn1.frame = CGRectMake(230, 200, 60, 30);

    [self.view addSubview:btn1];

    [btn1 addTarget:self action:@selector(click2) forControlEvents:UIControlEventTouchUpInside];

}

-(void)click

{

   

    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo

           onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error)

     {

         if (state == SSDKResponseStateSuccess)

         {

             

             NSLog(@"uid=%@",user.uid);

             NSLog(@"%@",user.credential);

             NSLog(@"token=%@",user.credential.token);

             NSLog(@"nickname=%@",user.nickname);

             NSLog(@"followerCount=%ld",user.followerCount);

             NSLog(@"friendCount=%lu",user.friendCount);

             

             lab = [[UILabel alloc]initWithFrame:CGRectMake(150, 300, 150, 30)];

             lab.text = user.nickname;

             [self.view addSubview:lab];

             

             lab1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 400, 150, 30)];

             lab1.text =[NSString stringWithFormat:@"%ld",user.followerCount];

             [self.view addSubview:lab1];

             

             lab2 = [[UILabel alloc]initWithFrame:CGRectMake(150, 500, 150, 30)];

             lab2.text =[NSString stringWithFormat:@"%ld",user.friendCount];

             [self.view addSubview:lab2];


             

             labname = [[UILabel alloc]initWithFrame:CGRectMake(50, 300, 50, 30)];

             labname.text = @"昵称:";

             [self.view addSubview:labname];

             

             labfan = [[UILabel alloc]initWithFrame:CGRectMake(50, 400, 100, 30)];

             labfan.text = @"粉丝数:";

             [self.view addSubview:labfan];

             

             labfriend = [[UILabel alloc]initWithFrame:CGRectMake(50, 500, 100, 30)];

             labfriend.text =@"好友数:";

             [self.view addSubview:labfriend];

             

             

            


         }

         

         else

         {

             NSLog(@"%@",error);

         }

         

     }];

}

-(void)click2

{

    [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];

    [lab removeFromSuperview];

    [lab1 removeFromSuperview];

    [lab2 removeFromSuperview];

    [labfan removeFromSuperview];

    [labfriend removeFromSuperview];

    [labname removeFromSuperview];

    

}




你可能感兴趣的:(新浪微博登录SDK)