iOS友盟第三方登录分享

需要引入框架

    1. SystemConfiguration.framework
    1. CoreGraphics.framework
    1. libsqlite3.dylib
    1. CoreTelephony.framework
    1. libstdc++.dylib,
    1. libz.dylib

下载最新的SDK

** 将UMSocial_Sdk-x.x.x的文件夹拖入工程目录下**
libUMSocial_Sdk-x.x.x.alibUMSocial_Sdk_comment_3.0.a库文件
** Header头文字**
SocialSDKXibxib文件
en.Iproj,zh-Hans.Iproj英文和中文语言文件
frameworks使用的第三方SDK,里面的Wechat,TencentOperAPI,TencentWeiboSSO,分别代表微信、手机QQ和腾讯微博SDK

[UMSocialDatasetAppKey:@"507fcab25270157b37000010"];//字符串@"507fcab25270157b37000010"为您的友盟分享的AppKey
//设置手机QQ的使用
[UMSocialConfigsetQQAppId:@"100371282"url:nilimportClasses:@[[QQApiInterfaceclass], [TencentOAuthclass]]];
//设置微信功能
[UMSocialConfigsetWXAppId:@"wx4868b35061f87885"url:nil];```
#pragmamark使用第三方登录需要重写下面两个方法
  • (void)applicationDidBecomeActive:(UIApplication*)application
    {
    //登录需要编写
    [UMSocialSnsServiceapplicationDidBecomeActive];
    }
  • (BOOL)application:(UIApplication)applicationopenURL:(NSURL)urlsourceApplication:(NSString*)sourceApplicationannotation:(id)annotation
    {
    return[UMSocialSnsServicehandleOpenURL:urlwxApiDelegate:nil];
    }```

pragma mark直接分享

- (IBAction)share:(id)sender
{
//设置分享内容与分享平台
//弹出UIActivityViewController样式的列表
[UMSocialSnsServicepresentSnsIconSheetView:selfappKey:NilshareText:@"要分享的内容"shareImage:nilshareToSnsNames:@[UMShareToQzone,UMShareToSina,UMShareToTencent,UMShareToRenren,
UMShareToSms,UMShareToEmail,UMShareToFacebook,UMShareToTwitter,UMShareToWechatSession,UMShareToWechatTimeline,
UMShareToQQ]delegate:nil];
}```
#pragmamark自定义分享平台的图标、文字、点击事件
  • (IBAction)diyPlatformInfo:(id)sender
    {
    //获取到新浪微博分享平台
    UMSocialSnsPlatformsinaPlatform= [UMSocialSnsPlatformManagergetSocialPlatformWithName:UMShareToSina];
    //设置平台图片
    sinaPlatform.bigImageName=@"新浪@2x.png";
    //设置平台名称
    sinaPlatform.displayName=@"新浪的微博";
    //设置点击平台图标的事件
    sinaPlatform.snsClickHandler=^(UIViewController
    presentingController,UMSocialControllerService*socialControllerService,BOOLisPresentInController){
    NSLog(@"点击了新浪微博分享");
    };
    //弹出UITableView样式的分享列表
    [UMSocialSnsServicepresentSnsController:selfappKey:nilshareText:@"要分享的内容"shareImage:nilshareToSnsNames:@[UMShareToSina]delegate:nil];
    }```

pragma mark设置分享的类型

- (IBAction)shareType:(id)sender
{
//设置分享音乐类型
[[UMSocialDatadefaultData].urlResourcesetResourceType:UMSocialUrlResourceTypeMusic];
//设置图片类型并附带网址
[[UMSocialDatadefaultData].urlResourcesetResourceType:UMSocialUrlResourceTypeImageurl:@"http://baike.steelhome.cn/uploads/200912/1262062983nmcUZA6K.jpg"];
//设置视频类型,并附带网址
[[UMSocialDatadefaultData].urlResourcesetResourceType:UMSocialUrlResourceTypeVideourl:@"http://www.baidu.com/video/benshankuaileying/4324343244320.mp4"];
//显示各个平台类型
[UMSocialSnsServicepresentSnsIconSheetView:selfappKey:NilshareText:@"要分享的内容"shareImage:nilshareToSnsNames:@[UMShareToSina]delegate:nil];
}

pragma mark分享到QQ

- (IBAction)shareToQQ:(id)sender
{
[UMSocialSnsServicepresentSnsIconSheetView:selfappKey:nilshareText:@"发送分享内容"shareImage:nilshareToSnsNames:@[UMShareToQQ]delegate:nil];
}

pragma mark微信分享

- (IBAction)shareWeiXin:(id)sender
{
//设置微信分享应用类型,用户点击消息将跳转到应用,或者到下载页面
//UMSocialWXMessageTypeImage为图片类型
[UMSocialDatadefaultData].extConfig.wxMessageType=UMSocialWXMessageTypeApp;
//分享图盘到微信朋友圈显示字数比较少,只显示分享标题
[UMSocialDatadefaultData].extConfig.title=@"朋友圈分享内容";
//显示分享平台
[UMSocialSnsServicepresentSnsController:selfappKey:nilshareText:@"分享的内容"shareImage:nilshareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline]delegate:nil];
}

pragma mark第三方登录

- (IBAction)otherLogin:(id)sender
{
//使用Sina微博账号登录
UMSocialSnsPlatform*snsPlatform= [UMSocialSnsPlatformManagergetSocialPlatformWithName:UMShareToSina];
snsPlatform.loginClickHandler(self,
[UMSocialControllerServicedefaultControllerService],YES,
^(UMSocialResponseEntity*response) {
NSLog(@"response is %@", response);
//如果是授权到新浪微博,SSO之后如果想获取用户的昵称、头像等需要再获取一次账户信息
[[UMSocialDataServicedefaultDataService]requestSocialAccountWithCompletion:^(UMSocialResponseEntity*response){
//打印用户昵称
NSLog(@"SinaWeibo's user name is%@",
[[[response.dataobjectForKey:@"accounts"]objectForKey:UMShareToSina]objectForKey:@"username"]);
}];
});
}```
![](http://upload-images.jianshu.io/upload_images/1264820-30fa467ff5f2271c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

你可能感兴趣的:(iOS友盟第三方登录分享)