标签:
一、在项目中要配置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