需到各平台申请接口
微信:https://open.weixin.qq.com
QQ: http://open.qq.com
微博:http://open.weibo.com
- 设置友盟Key
[UMSocialData setAppKey:UMengSocialAppKey];
- 打开调试log的开关
[UMSocialData openLog:YES];
- 支持不同的屏幕方向
[UMSocialConfig setSupportedInterfaceOrientations:UIInterfaceOrientationMaskAll];
- 设置微信AppId,设置分享url
[UMSocialWechatHandler setWXAppId:WeixinAppkey
appSecret:WeixinSecret
url:@"http://www.baidu.com"];
- 设置分享到QQ空间的应用Id和分享url
[UMSocialQQHandler setQQWithAppId:QQAppID
appKey:QQAppkey
url:@"http://www.baidu.com"];
- 若用户没安装相关客户端,就隐藏掉
[UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToSina,UMShareToQQ, UMShareToWechatSession, UMShareToWechatTimeline,UMShareToQzone]];
- 微信相关设置
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
[UMSocialData defaultData].extConfig.wechatSessionData.url = url; //微信好友
[UMSocialData defaultData].extConfig.wechatTimelineData.url = url; //朋友圈
[UMSocialData defaultData].extConfig.title = @"title WeiXin";
- 手机QQ、QQ空间相关设置
[UMSocialData defaultData].extConfig.qqData.qqMessageType = UMSocialQQMessageTypeDefault;
[UMSocialData defaultData].extConfig.qqData.title = @"title QQ";
[UMSocialData defaultData].extConfig.qqData.url = url;
[UMSocialData defaultData].extConfig.qzoneData.title = @"title QZone";
[UMSocialData defaultData].extConfig.qzoneData.url = url;
- 新浪微博相关设置
[[UMSocialData defaultData].extConfig.sinaData.urlResource setResourceType:UMSocialUrlResourceTypeWeb url:url];
- 分享
[UMSocialSnsService presentSnsIconSheetView:self
appKey:UMengSocialAppKey
shareText:[NSString stringWithFormat:@"...分享自:http://www.baidu.com"]
shareImage:nil
shareToSnsNames:@[UMShareToWechatTimeline, UMShareToWechatSession, UMShareToQQ,UMShareToQzone, UMShareToSina,UMShareToSms,UMShareToEmail]
delegate:self];
- 实现UMSocialUIDelegate代理方法
- (void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
if (response.responseCode == UMSResponseCodeSuccess) {
NSLog(@"分享成功");
} else {
NSLog(@"分享失败");
}
}```
- 登录
UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response)
{
if (response.responseCode == UMSResponseCodeSuccess)
{
UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToWechatSession];
NSLog(@"微信 snsAccount \n%@",snsAccount);
NSLog(@"微信第三方原始response response.thirdPlatformResponse %@",response.thirdPlatformResponse);
NSLog(@"微信第三方返回的用户详细信息 response.thirdPlatformUserProfile %@",response.thirdPlatformUserProfile);
// 处理数据
}
});
参见[友盟SDK5.2.1版本 官方文档](http://dev.umeng.com/social/ios/quick-integration?spm=0.0.0.0.2WVixn)