新浪微博+SDK---登录


//根据SDK导入所需要的包,库。



APPdelegate--------------:

#import "ViewController.h"


#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>

//新浪微博SDK头文件

#import "WeiboSDK.h"

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

//初始化视图控制器

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

    //初始化导航控制器

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

    //初始话跟试图控制器

    self.window.rootViewController=nav;

    

    

    

    

    [ShareSDK registerApp:@"aeada91becf1"

     

          activePlatforms:@[

                            @(SSDKPlatformTypeSinaWeibo)]

     

                 onImport:nil

     

          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)

     {

         

         switch (platformType)

         {

             case SSDKPlatformTypeSinaWeibo:

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

                 [appInfo SSDKSetupSinaWeiboByAppKey:@"4141249222"

                                           appSecret:@"4aea86781c861b007b96d0a031728ac9"

                  

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

                                            authType:SSDKAuthTypeBoth];

                 break;

             

             default:

                 break;

         }

     }];

    

    return YES;





------viewContrillers


#import <ShareSDK/ShareSDK.h>

#import <ShareSDKConnector/ShareSDKConnector.h>


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    //背景色

    self.view.backgroundColor=[UIColor whiteColor];

    //导航标题

    self.navigationItem.title=@"新浪";

    

    UIButton *b1=[UIButton buttonWithType:UIButtonTypeRoundedRect];

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

    b1.backgroundColor=[UIColor orangeColor];

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

    [b1 addTarget:self action:@selector(click1) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:b1];

    

    UIButton *b2=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    b2.frame=CGRectMake(250, 200, 80, 30);

    b2.backgroundColor=[UIColor orangeColor];

    [b2 setTitle:@"退出登陆" forState:UIControlStateNormal];

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

    [self.view addSubview:b2];

    

    

    

    

}


//微博登陆

-(void)click1{

    

    [ShareSDK getUserInfo:SSDKPlatformTypeSinaWeibo onStateChanged:^(SSDKResponseState state, SSDKUser *user, NSError *error) {

        

        if (state==SSDKResponseStateSuccess) {

            

            NSLog(@"昵称:%@",user.nickname);

            NSLog(@"粉丝数:%ld",user.followerCount);

            NSLog(@"好友数:%ld",user.friendCount);

            

            UILabel *l1=[[UILabel alloc] init];

            l1.frame=CGRectMake(100, 300, 200, 30);

            l1.backgroundColor=[UIColor greenColor];

            l1.text=[NSString stringWithFormat:@"昵称:%@",user.nickname];

            [self.view addSubview:l1];

            

            UILabel *l2=[[UILabel alloc] init];

            l2.frame=CGRectMake(100, 350, 200, 30);

            l2.backgroundColor=[UIColor greenColor];

            l2.text=[NSString stringWithFormat:@"粉丝数:%ld",user.followerCount];

            [self.view addSubview:l2];

            

            UILabel *l3=[[UILabel alloc] init];

            l3.frame=CGRectMake(100, 400, 200, 30);

            l3.backgroundColor=[UIColor greenColor];

            l3.text=[NSString stringWithFormat:@"好友数:%ld",user.friendCount];

            [self.view addSubview:l3];



            

        }

        

    }];



}


//退出登陆

-(void)click2{

    

    [ShareSDK cancelAuthorize:SSDKPlatformTypeSinaWeibo];

    

        

    

}


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