码迷,mamicode.com
首页 > 其他好文 > 详细

友盟第三方登录

时间:2015-10-09 21:30:14      阅读:976      评论:0      收藏:0      [点我收藏+]

标签:

一、在项目中要配置APPID和appKey

#import "ViewController.h"
#import "UMSocial.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

#pragma mark - 第三方登录
- (IBAction)sinaLogin {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        //          获取微博用户名、uid、token等
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
            
        }});
}

- (IBAction)qqLogin {
    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToQQ];
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        if (response.responseCode == UMSResponseCodeSuccess) {
            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToQQ];
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
        }});
}


#pragma mark - 微信分享
- (IBAction)shareToSession {
    [self shareToWeixin:UMShareToWechatSession];
}

- (IBAction)shareToTimeline {
    [self shareToWeixin:UMShareToWechatTimeline];
}

- (void)shareToWeixin:(NSString *)shareToWeixin
{
    
    UIImage *image = [UIImage imageNamed:@"dzq_icon.jpg"];
    [[UMSocialDataService defaultDataService] postSNSWithTypes:@[shareToWeixin] content:@"梦想还是要有的,万一实现了呢" image:image location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
        if (response.responseCode == UMSResponseCodeSuccess) {
            NSLog(@"分享成功!");
        }
    }];
}

 

友盟第三方登录

标签:

原文地址:http://www.cnblogs.com/dmcode/p/4865039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!