第一步: 用cocoapods导入框架
target 'tests' do
# U-Share SDK UI模块(分享面板,建议添加)
pod ‘UMengUShare/UI’
# 集成微信(完整版14.4M)
pod ‘UMengUShare/Social/WeChat'
# 集成QQ(完整版7.6M)
pod ‘UMengUShare/Social/QQ'
# 集成新浪微博(完整版25.3M)
pod ‘UMengUShare/Social/Sina'
# 集成Facebook/Messenger
pod ‘UMengUShare/Social/Facebook'
# 集成Twitter
pod ‘UMengUShare/Social/Twitter'
# 集成腾讯微博
pod ‘UMengUShare/Social/TencentWeibo'
# 加入IDFA获取
pod ‘UMengUShare/Plugin/IDFA'
end
第二步:设置白名单 和https 设置
打开info.plist文件
HTTPS 设置
<key>
NSAppTransportSecurity
</key>
<dict>
<key> NSAllowsArbitraryLoads </key>
<true/>
<dict>
<key> NSAllowsArbitraryLoads </key>
<true/>
</dict>
白名单设置
<key>
LSApplicationQueriesSchemes
</key>
<array>
<string> linkedin </string>
<string> linkedin-sdk2 </string>
<string> linkedin-sdk </string>
<string> wechat </string>
<string> weixin </string>
<string> sinaweibohd </string>
<string> sinaweibo </string>
<string> sinaweibosso </string>
<string> weibosdk </string>
<string> weibosdk2.5 </string>
<string> mqqapi </string>
<string> mqq </string>
<string> mqqOpensdkSSoLogin </string>
<string> mqqconnect </string>
<string> mqqopensdkdataline </string>
<string> mqqopensdkgrouptribeshare </string>
<string> mqqopensdkfriend </string>
<string> mqqopensdkapi </string>
<string> mqqopensdkapiV2 </string>
<string> mqqopensdkapiV3 </string>
<string> mqqopensdkapiV4 </string>
<string> mqzoneopensdk </string>
<string> wtloginmqq </string>
<string> wtloginmqq2 </string>
<string> mqqwpa </string>
<string> mqzone </string>
<string> mqzonev2 </string>
<string> mqzoneshare </string>
<string> wtloginqzone </string>
<string> mqzonewx </string>
<string> mqzoneopensdkapiV2 </string>
<string> mqzoneopensdkapi19 </string>
<string> mqzoneopensdkapi </string>
<string> mqqbrowser </string>
<string> mttbrowser </string>
<string> TencentWeibo </string>
<string> tencentweiboSdkv2 </string>
<string> alipay </string>
<string> alipayshare </string>
<string> renrenios </string>
<string> renrenapi </string>
<string> renren </string>
<string> renreniphone </string>
<string> laiwangsso </string>
<string> yixin </string>
<string> yixinopenapi </string>
<string> yixinoauth </string>
<string> yixinfav </string>
<string> laiwangsso </string>
<string> instagram </string>
<string> whatsapp </string>
<string> line </string>
<string> tumblr </string>
<string> fbapi </string>
<string> fb-messenger-api </string>
<string> fbauth2 </string>
<string> fbshareextension </string>
<string> kakao6d5e4ca98ba3b944020c2c90953318e9 </string>
<string> kakaokompassauth </string>
<string> storykompassauth </string>
<string> kakaolink </string>
<string> kakaotalk-4.5.0 </string>
<string> kakaostory-2.9.0 </string>
<string> pinterestsdk.v1 </string>
<string> dingtalk </string>
<string> dingtalk-open </string>
<!-- 印象笔记 -->
<string> evernote </string>
<string> en </string>
<string> enx </string>
<string> evernotecid </string>
<string> evernotemsg </string>
<!-- 有道云笔记 -->
<string> youdaonote </string>
<string> ynotedictfav </string>
<string> com.youdao.note.todayViewNote </string>
<string> ynotesharesdk </string>
<!-- gplus-->
<string> gplus </string>
<!-- pocket-->
<string> pocket </string>
<string> readitlater </string>
<string> pocket-oauth-v1 </string>
<string> fb131450656879143 </string>
<string> en-readitlater-5776 </string>
<string> com.ideashower.ReadItLaterPro3 </string>
<string> com.ideashower.ReadItLaterPro </string>
<string> com.ideashower.ReadItLaterProAlpha </string>
<string> com.ideashower.ReadItLaterProEnterprise </string>
<!-- vk-->
<string> vk </string>
<string> vk-share </string>
<string> vkauthorize </string>
<!-- facebookMessage-->
<string> fbauth </string>
<string> fbauth2 </string>
<string> fb-messenger-api20140430 </string>
<string> fb-messenger-platform </string>
<string> fb-messenger-platform-20150128 </string>
<string> fb-messenger-platform-20150218 </string>
<string> fb-messenger-platform-20150305 </string>
<string> fb-messenger-share </string>
<array>
<string> linkedin </string>
<string> linkedin-sdk2 </string>
<string> linkedin-sdk </string>
<string> wechat </string>
<string> weixin </string>
<string> sinaweibohd </string>
<string> sinaweibo </string>
<string> sinaweibosso </string>
<string> weibosdk </string>
<string> weibosdk2.5 </string>
<string> mqqapi </string>
<string> mqq </string>
<string> mqqOpensdkSSoLogin </string>
<string> mqqconnect </string>
<string> mqqopensdkdataline </string>
<string> mqqopensdkgrouptribeshare </string>
<string> mqqopensdkfriend </string>
<string> mqqopensdkapi </string>
<string> mqqopensdkapiV2 </string>
<string> mqqopensdkapiV3 </string>
<string> mqqopensdkapiV4 </string>
<string> mqzoneopensdk </string>
<string> wtloginmqq </string>
<string> wtloginmqq2 </string>
<string> mqqwpa </string>
<string> mqzone </string>
<string> mqzonev2 </string>
<string> mqzoneshare </string>
<string> wtloginqzone </string>
<string> mqzonewx </string>
<string> mqzoneopensdkapiV2 </string>
<string> mqzoneopensdkapi19 </string>
<string> mqzoneopensdkapi </string>
<string> mqqbrowser </string>
<string> mttbrowser </string>
<string> TencentWeibo </string>
<string> tencentweiboSdkv2 </string>
<string> alipay </string>
<string> alipayshare </string>
<string> renrenios </string>
<string> renrenapi </string>
<string> renren </string>
<string> renreniphone </string>
<string> laiwangsso </string>
<string> yixin </string>
<string> yixinopenapi </string>
<string> yixinoauth </string>
<string> yixinfav </string>
<string> laiwangsso </string>
<string> instagram </string>
<string> whatsapp </string>
<string> line </string>
<string> tumblr </string>
<string> fbapi </string>
<string> fb-messenger-api </string>
<string> fbauth2 </string>
<string> fbshareextension </string>
<string> kakao6d5e4ca98ba3b944020c2c90953318e9 </string>
<string> kakaokompassauth </string>
<string> storykompassauth </string>
<string> kakaolink </string>
<string> kakaotalk-4.5.0 </string>
<string> kakaostory-2.9.0 </string>
<string> pinterestsdk.v1 </string>
<string> dingtalk </string>
<string> dingtalk-open </string>
<!-- 印象笔记 -->
<string> evernote </string>
<string> en </string>
<string> enx </string>
<string> evernotecid </string>
<string> evernotemsg </string>
<!-- 有道云笔记 -->
<string> youdaonote </string>
<string> ynotedictfav </string>
<string> com.youdao.note.todayViewNote </string>
<string> ynotesharesdk </string>
<!-- gplus-->
<string> gplus </string>
<!-- pocket-->
<string> pocket </string>
<string> readitlater </string>
<string> pocket-oauth-v1 </string>
<string> fb131450656879143 </string>
<string> en-readitlater-5776 </string>
<string> com.ideashower.ReadItLaterPro3 </string>
<string> com.ideashower.ReadItLaterPro </string>
<string> com.ideashower.ReadItLaterProAlpha </string>
<string> com.ideashower.ReadItLaterProEnterprise </string>
<!-- vk-->
<string> vk </string>
<string> vk-share </string>
<string> vkauthorize </string>
<!-- facebookMessage-->
<string> fbauth </string>
<string> fbauth2 </string>
<string> fb-messenger-api20140430 </string>
<string> fb-messenger-platform </string>
<string> fb-messenger-platform-20150128 </string>
<string> fb-messenger-platform-20150218 </string>
<string> fb-messenger-platform-20150305 </string>
<string> fb-messenger-share </string>
</array>
schedule设置
<key>
CFBundleURLTypes
</key>
<array>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string></string>
<key> CFBundleURLSchemes </key>
<array>
<string> wb3921700954 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> weixin </string>
<key> CFBundleURLSchemes </key>
<array>
<string> wxdc1e388c3822c80b </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> tencent1105821097 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> alipayShare </string>
<key> CFBundleURLSchemes </key>
<array>
<string> ap2015111700822536 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> yixinSocialSDK </string>
<key> CFBundleURLSchemes </key>
<array>
<string> yx35664bdff4db42c2b7be1e29390c1a06 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> QQ41E97DA9 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> yx35664bdff4db42c2b7be1e29390c1a06 </string>
</array>
</dict>
<dict>
<key> CFBundleURLSchemes </key>
<array>
<string> li4768945 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> Laiwang </string>
<key> CFBundleURLSchemes </key>
<array>
<string> 8112117817424282305 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> fb506027402887373 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> rmcom.umeng.SocialSDK </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> qzoneScheme </string>
<key> CFBundleURLSchemes </key>
<array>
<string> mqzone </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> tencentApiIdentifier </string>
<key> CFBundleURLSchemes </key>
<array>
<string> tencent100424468.content </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> liyinIdentifier </string>
<key> CFBundleURLSchemes </key>
<array>
<string> li4768945 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> kakao6d5e4ca98ba3b944020c2c90953318e9 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> dingtalk </string>
<key> CFBundleURLSchemes </key>
<array>
<string> dingoalmlnohc0wggfedpk </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> vk5786123 </string>
<key> CFBundleURLSchemes </key>
<array>
<string> vk5786123 </string>
</array>
</dict>
<array>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string></string>
<key> CFBundleURLSchemes </key>
<array>
<string> wb3921700954 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> weixin </string>
<key> CFBundleURLSchemes </key>
<array>
<string> wxdc1e388c3822c80b </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> tencent1105821097 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> alipayShare </string>
<key> CFBundleURLSchemes </key>
<array>
<string> ap2015111700822536 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> yixinSocialSDK </string>
<key> CFBundleURLSchemes </key>
<array>
<string> yx35664bdff4db42c2b7be1e29390c1a06 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> QQ41E97DA9 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> yx35664bdff4db42c2b7be1e29390c1a06 </string>
</array>
</dict>
<dict>
<key> CFBundleURLSchemes </key>
<array>
<string> li4768945 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> Laiwang </string>
<key> CFBundleURLSchemes </key>
<array>
<string> 8112117817424282305 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> fb506027402887373 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> rmcom.umeng.SocialSDK </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> qzoneScheme </string>
<key> CFBundleURLSchemes </key>
<array>
<string> mqzone </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> tencentApiIdentifier </string>
<key> CFBundleURLSchemes </key>
<array>
<string> tencent100424468.content </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> liyinIdentifier </string>
<key> CFBundleURLSchemes </key>
<array>
<string> li4768945 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLSchemes </key>
<array>
<string> kakao6d5e4ca98ba3b944020c2c90953318e9 </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> dingtalk </string>
<key> CFBundleURLSchemes </key>
<array>
<string> dingoalmlnohc0wggfedpk </string>
</array>
</dict>
<dict>
<key> CFBundleTypeRole </key>
<string> Editor </string>
<key> CFBundleURLName </key>
<string> vk5786123 </string>
<key> CFBundleURLSchemes </key>
<array>
<string> vk5786123 </string>
</array>
</dict>
</array>
第三步:appdelegate中初始化 (设置友盟appkey 和分享的各个平台的id 和 password)
导入头文件
#import <UMSocialCore/UMSocialCore.h>
[[UMSocialManager defaultManager] setUmSocialAppkey:@"574eadf0e0f55aecbc003450a"];
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:@"http://mobile.umeng.com/social"];
/*
* 移除相应平台的分享,如微信收藏
*/
//[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
/* 设置分享到QQ互联的appID
* U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
*/
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1105821097"/*设置QQ平台的appID*/ appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
/* 设置新浪的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954" appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
/* 钉钉的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DingDing appKey:@"dingoalmlnohc0wggfedpk" appSecret:nil redirectURL:nil];
/* 支付宝的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:@"2015111700822536" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
/* 设置易信的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_YixinSession appKey:@"yx35664bdff4db42c2b7be1e29390c1a06" appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];
/* 设置点点虫(原来往)的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_LaiWangSession appKey:@"8112117817424282305" appSecret:@"9996ed5039e641658de7b83345fee6c9" redirectURL:@"http://mobile.umeng.com/social"];
/* 设置领英的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Linkedin appKey:@"81t5eiem37d2sc" appSecret:@"7dgUXPLH8kA8WHMV" redirectURL:@"https://api.linkedin.com/v1/people"];
/* 设置Twitter的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Twitter appKey:@"fB5tvRpna1CKK97xZUslbxiet" appSecret:@"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K" redirectURL:nil];
/* 设置Facebook的appKey和UrlString */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"506027402887373" appSecret:nil redirectURL:@"http://www.umeng.com/social"];
/* 设置Pinterest的appKey */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Pinterest appKey:@"4864546872699668063" appSecret:nil redirectURL:nil];
/* dropbox的appKey */
[[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_DropBox appKey:@"k4pn9gdwygpy4av" appSecret:@"td28zkbyb9p49xu" redirectURL:@"https://mobile.umeng.com/social"];
/* vk的appkey */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_VKontakte appKey:@"5786123" appSecret:nil redirectURL:nil];
更换你的友盟key 和各个平台的key secret
第四步:在需要做分享的界面调用分享面板(点击button 调用该代码)
[UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_Sina),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_Facebook),@(UMSocialPlatformType_Twitter)]]; // 设置需要分享的平台
//显示分享面板
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
// 根据获取的platformType确定所选平台进行下一步操作
NSLog(@"回调");
NSLog(@"%ld",(long)platformType);
NSLog(@"%@",userInfo);
//创建分享消息对象
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//创建网页内容对象
NSString* thumbURL = @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"博文你个逗比" descr:@"哈哈哈哈哈" thumImage:thumbURL];
//设置网页地址
shareObject.webpageUrl = @"http://mobile.umeng.com/social";
//分享消息对象设置分享内容对象
messageObject.shareObject = shareObject;
//调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
NSLog(@"调用分享接口");
if (error) {
NSLog(@"调用失败%@",error);
UMSocialLogInfo(@"************Share fail with error %@*********",error);
}else{
NSLog(@"调用成功");
if ([data isKindOfClass:[UMSocialShareResponse class]]) {
UMSocialShareResponse *resp = data;
//分享结果消息
UMSocialLogInfo(@"response message is %@",resp.message);
//第三方原始返回的数据
UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
}else{
UMSocialLogInfo(@"response data is %@",data);
}
}
// [self alertWithError:error];
}];
}];