友盟分享文檔傳送門:https://developer.umeng.com/docs/66632/detail/66825
文章目錄結構:
---1、集成SDK
-----1.1 自動集成(cocoapods)
-----1.2 手動集成
-------1.2.1 下載對應的SDK(我用的只有分享SDK)
-------1.2.2 導入SDK到項目中
-------1.2.3 添加項目配置
-------1.2.4?加入依賴系統庫
---2、配置SSO白名單:設置白名單為的是能夠獲取第三方平臺的授權
---3、配置URL Scheme:目的是能夠在分享結束后跳回到自己的app中
---4、初始化設置
---5、調用分享方法
---6、集成友盟分享遇到的問題以及解決方案
1、集成SDK
1.1 自動集成(cocoapods)
? ? ? ?見文檔。
1.2 手動集成
? ? 1.2.1 下載對應的SDK(我用的只有分享SDK)
1.2.2 導入SDK到項目中
1.2.3 添加項目配置
在Other Linker Flags加入-ObjC ,注意不要寫為-Objc
-ObjC屬于鏈接庫必備參數,如果不加此項,會導致庫文件無法被正確鏈接,SDK無法正常運行
1.2.4?加入依賴系統庫
加入以下系統庫:
libsqlite3.tbd
CoreGraphics.framework
(注意:第三方平臺庫添加,根據集成的不同平臺加入相關的依賴庫,具體可看文檔)
2、配置SSO白名單:設置白名單為的是能夠獲取第三方平臺的授權
在項目中的info.plist中加入應用白名單,右鍵info.plist選擇source code打開,加入以下代碼(可根據自身需要進行刪減):
<key>LSApplicationQueriesSchemes</key>
<array>
? ? <!-- 微信 URL Scheme 白名單-->
? ? <string>wechat</string>
? ? <string>weixin</string>
? ? <!-- 新浪微博 URL Scheme 白名單-->
? ? <string>sinaweibohd</string>
? ? <string>sinaweibo</string>
? ? <string>sinaweibosso</string>
? ? <string>weibosdk</string>
? ? <string>weibosdk2.5</string>
? ? <!-- QQ、Qzone URL Scheme 白名單-->
? ? <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>tim</string>
? ? <string>timapi</string>
? ? <string>timopensdkfriend</string>
? ? <string>timwpa</string>
? ? <string>timgamebindinggroup</string>
? ? <string>timapiwallet</string>
? ? <string>timOpensdkSSoLogin</string>
? ? <string>wtlogintim</string>
? ? <string>timopensdkgrouptribeshare</string>
? ? <string>timopensdkapiV4</string>
? ? <string>timgamebindinggroup</string>
? ? <string>timopensdkdataline</string>
? ? <string>wtlogintimV1</string>
? ? <string>timapiV1</string>
? ? <!-- 支付寶 URL Scheme 白名單-->
? ? <string>alipay</string>
? ? <string>alipayshare</string>
? ? <!-- 釘釘 URL Scheme 白名單-->
? ? ? <string>dingtalk</string>
? ? ? <string>dingtalk-open</string>
? ? <!--Linkedin URL Scheme 白名單-->
? ? <string>linkedin</string>
? ? <string>linkedin-sdk2</string>
? ? <string>linkedin-sdk</string>
? ? <!-- 點點蟲 URL Scheme 白名單-->
? ? <string>laiwangsso</string>
? ? <!-- 易信 URL Scheme 白名單-->
? ? <string>yixin</string>
? ? <string>yixinopenapi</string>
? ? <!-- instagram URL Scheme 白名單-->
? ? <string>instagram</string>
? ? <!-- whatsapp URL Scheme 白名單-->
? ? <string>whatsapp</string>
? ? <!-- line URL Scheme 白名單-->
? ? <string>line</string>
? ? <!-- Facebook URL Scheme 白名單-->
? ? <string>fbapi</string>
? ? <string>fb-messenger-api</string>
? ? <string>fb-messenger-share-api</string>
? ? <string>fbauth2</string>
? ? <string>fbshareextension</string>
? ? <!-- Kakao URL Scheme 白名單-->?
? ? <!-- 注:以下第一個參數需替換為自己的kakao appkey-->
? ? <!-- 格式為 kakao + "kakao appkey"-->? ?
? ? <string>kakaofa63a0b2356e923f3edd6512d531f546</string>
? ? <string>kakaokompassauth</string>
? ? <string>storykompassauth</string>
? ? <string>kakaolink</string>
? ? <string>kakaotalk-4.5.0</string>
? ? <string>kakaostory-2.9.0</string>
? <!-- pinterest URL Scheme 白名單-->?
? ? <string>pinterestsdk.v1</string>
? <!-- Tumblr URL Scheme 白名單-->?
? ? <string>tumblr</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>
? <!-- Google+-->
? ? <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>
? <!-- VKontakte-->
? ? <string>vk</string>
? ? <string>vk-share</string>
? ? <string>vkauthorize</string>
? <!-- Twitter-->
? ? <string>twitter</string>
? ? <string>twitterauth</string>
</array>
3、配置URL Scheme:目的是能夠在分享結束后跳回到自己的app中
·配置第三方平臺URL Scheme未列出則不需設置
4、初始化設置
4.1 在項目 AppDelegate.m 中引用#import <UMShare/UMShare.h>和#import?<UMCommon/UMCommon.h>
4.2 在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}方法中,設置友盟appkey并調用-(void)confitUShareSettings方法:
- (void)configUSharePlatforms {
?? ?/* 設置微信的appKey和appSecret */
? ? [[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];
}
5、調用分享方法
-(void)toShare {
/** 設置分享面板圖標的排序,可忽略使用默認排序 */
//? ? NSArray *baseDisplaySnsPlatforms = @[@(UMSocialPlatformType_WechatSession),
//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @(UMSocialPlatformType_QQ)
//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ];
//? ? [UMSocialUIManager setPreDefinePlatforms:baseDisplaySnsPlatforms];
? ? //顯示分享面板
? ? [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) { ? ? ? ?
????????//創建分享消息對象
? ? ? ? UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
? ? ? ? //創建網頁內容對象
? ? ? ? UMShareWebpageObject*shareObject = [UMShareWebpageObjectshareObjectWithTitle:@"挑戰你的記憶力"descr:@"魚的記憶有七秒,你的呢?"thumImage:[UIImage imageNamed:@"loginIcon"]];
? ? ? ? //設置網頁地址
? ? ? ? shareObject.webpageUrl=kUpdateLine;?
? ? ? ?//分享消息對象設置分享內容對象
? ? ? ? messageObject.shareObject= shareObject;
? ? ? ? //調用分享接口
? ? ? ? [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:nil completion:^(id data, NSError *error)
?? ? ? ? {
?? ? ? ? ? ? NSLog(@"%@",data);
?? ? ? ? ? ? if(error) {
?? ? ? ? ? ? ? ? UMSocialLogInfo(@"************Share fail with error %@*********",error);
?? ? ? ? ? ? }
?? ? ? ? ? ? if([dataisKindOfClass:[UMSocialShareResponseclass]]) {
?? ? ? ? ? ? ? ? UMSocialShareResponse*resp = data;
?? ? ? ? ? ? ? ? //分享結果消息
?? ? ? ? ? ? ? ? UMSocialLogInfo(@"response message is %@",resp.message);
?? ? ? ? ? ? ? ? //第三方原始返回的數據
?? ? ? ? ? ? ? ? UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
?? ? ? ? ? ? }else{
?? ? ? ? ? ? ? ? UMSocialLogInfo(@"response data is %@",data);
?? ? ? ? ? ? }
?? ? ? ? }];
? ? }];
}
6、集成友盟分享遇到的問題以及解決方案
6.1 問:點擊分享后沒有彈出分享面板?
? ? ? 答:
6.2 問:分享面板沒有任何第三方平臺的圖標?
? ? ? 答:①確認真機已經安裝對應的應用;
? ? ? ? ? ? ? ②確認APPDelegate.m中調用了-(void)confitUShareSettings方法;