美文网首页程序员
关于ShareSDK的使用

关于ShareSDK的使用

作者: Ghstart | 来源:发表于2014-03-13 16:15 被阅读3061次

由于公司极度恶心的要使用网易的授权登录,找了好久,最终选择了ShareSDK,发现还是很好用的。

直接代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //注册shareSDk
    [ShareSDK registerApp:@"xxxxx"];
    //sina
    [ShareSDK connectSinaWeiboWithAppKey:@"38xxxx979"
                               appSecret:@"7df5xxxxbf7c"
                             redirectUri:@"http://www.baidu.com"];
    //网易
    [ShareSDK connect163WeiboWithAppKey:@"T5EI7BXe13vfyDuy"
                              appSecret:@"gZxwyNOvjFYpxwwlnuizHRRtBRZ2lV1j"
                            redirectUri:@"http://www.shareSDK.cn"];
    
    //人人
    [ShareSDK connectRenRenWithAppId:@"226427"
                              appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
                           appSecret:@"f29df781abdd4f49beca5a2194676ca4"
                   renrenClientClass:[RennClient class]];
    
    //QQ空间
    [ShareSDK connectQZoneWithAppKey:@"100371282"
                           appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    
    //这是模拟服务器的具体在www.parse.com上找到
    [Parse setApplicationId:@"Arqhxxxxx26seU9Nb"
                  clientKey:@"ixKhwYxxxxp9FHdf"];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    self.window.rootViewController = [[FirViewController alloc] init];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

2.在viewController中

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(100, 50, 100, 100);
    [button setTitle:@"Sina授权" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

-(void)buttonAction:(UIButton *)button
{
    if ([ShareSDK hasAuthorizedWithType:ShareTypeSinaWeibo]) {
        MainViewController *mainVC = [[MainViewController alloc] init];
        [self presentViewController:mainVC animated:YES completion:NULL];
        
    }else{
        [ShareSDK getUserInfoWithType:ShareTypeSinaWeibo
                          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)
                                           {
                                               PFObject *newUser = [PFObject objectWithClassName:@"UserInfo"];
                                               [newUser setObject:[userInfo uid] forKey:@"uid"];
                                               [newUser setObject:[userInfo nickname] forKey:@"name"];
                                               [newUser setObject:[userInfo profileImage] forKey:@"profileImage"];
                                               [newUser saveInBackground];
                                               
                                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello"
                                                                                                   message:@"欢迎注册"
                                                                                                  delegate:nil
                                                                                         cancelButtonTitle:@"知道了"
                                                                                         otherButtonTitles:nil];
                                               [alertView show];
                                           }else
                                           {
                                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello"
                                                                                                   message:@"欢迎回来"
                                                                                                  delegate:nil
                                                                                         cancelButtonTitle:@"知道了"
                                                                                         otherButtonTitles:nil];
                                               [alertView show];
                                           }
                                           
                                       }];
                                       
                                       //                                   MainViewController *mainVC  = [[MainViewController alloc] init];
                                       //                                   [self presentViewController:mainVC animated:YES completion:NULL];
                                   }
                               }];

    }
    
}

详情可在ShareSDK的官网上视频中有讲解。

相关文章

  • 关于分享的小见解

    关于分享----shareSDK使用中遇到的一些问题 首先为shareSDK打个广告,shareSDK拥有下面这些...

  • 关于ShareSDK的使用

    由于公司极度恶心的要使用网易的授权登录,找了好久,最终选择了ShareSDK,发现还是很好用的。 直接代码 2.在...

  • 开发中问题及解决方法

    使用ShareSDK [WXApi isWXAppInstalled]一直返回NO问题使用ShareSDK集成了微...

  • 第三方的知识网址记录

    1)关于分享的网站链接:http://sharesdk.mob.com/#/sharesdk 2)关于获取短信验证...

  • 集成Sharesdk报[MOB.. setProductID:]

    关于sharesdk 导入报[MOB.. setProductID]错误 项目开发用到 ShareSDK 了,但是...

  • ShareSDK

    使用ShareSDK授权相关功能实现用户第三方登录。流程如下所示: 1.使用ShareSDK中的hasAuthor...

  • ShareSDK 分享

    ShareSDK-for-iOS 比较方便使用

  • Android ShareSDK桥接技术

    ShareSDK本身基于android原生上集成使用的,但是为了能让广大开发者可以在各种引擎上使用ShareSDK...

  • 嘟嘟牛在线App踩过的坑

    ShareSDK分享 问题1:最近使用ShareSDK经常出现微信不能分享? 答:thumbImage: 这个要设...

  • iOS关于sharesdk的集成和使用

    一、sharesdk是一个做第三方分享的框架,这个框架可以分享到主流的第三方平台上面二、sharesdk的集成:首...

网友评论

    本文标题:关于ShareSDK的使用

    本文链接:https://www.haomeiwen.com/subject/kejktttx.html