跳轉(zhuǎn)到app都需要添加到白名單
在不使用第三方的情況下暖呕,采用系統(tǒng)原生的方法,實(shí)現(xiàn)分享功能。有兩種方式: 一種是使用UIActivityViewController
孩擂,另外一種是使用Social框架中的SLComposeViewController
從iOS11開始编矾,系統(tǒng)不允許跳過前面的選擇面板直接進(jìn)行第三方平臺(tái)分享(實(shí)際上是來到了但立刻被dismiss了)熟史,所以,iOS11后只能采用第一種方式窄俏!
UIActivityViewController
: 來彈出分享面板
SLComposeViewController
: 來跳過分享面板直接進(jìn)行第三方平臺(tái)分享
因需求需要 , 需要調(diào)研下列幾個(gè)國外社區(qū)三方應(yīng)用的分享.
-
Facebook
- 白名單
<string>fbshareextension</string> <string>fb</string> <string>fb2298965036780837</string> <string>fbapi</string> <string>fbapi20130214</string> <string>fbapi20130410</string> <string>fbapi20130702</string> <string>fbapi20131010</string> <string>fbapi20131219</string> <string>fbapi20140410</string> <string>fbapi20140116</string> <string>fbapi20150313</string> <string>fbapi20150629</string> <string>fbauth</string> <string>fbauth2</string>
- 系統(tǒng)分享:
activityType = com.apple.UIKit.activity.PostToFacebook
- 系統(tǒng)分享支持url 圖片 title
- iOS11之后國行手機(jī)無法測試
- SDK分享:
- 可獲得成功/失敗/取消回調(diào)
- 不能啟動(dòng)native的分享窗口, 那樣無法獲得分享完成的postId
-
FBSDKShareDialog
(分享彈窗) \FBSDKShareLinkContent
(分享內(nèi)容)
- 網(wǎng)頁分享:
- https://www.facebook.com/dialog/share?app_id={app_id}&display={page_type}&href={url}&redirect_uri={redirect_url}
- https://m.facebook.com/sharer/sharer.php?u={url}
- 回調(diào) (完成重定向至:
facebook.com/dialog/close_window
\facebook.com/dialog/return/close
) - 參考鏈接: https://github.com/bradvin/social-share-urls#facebook
-
Messenger
- 白名單
<string>fb-messenger-share-api</string> <string>fb-messenger-platform-20150128</string> <string>fb-messenger-platform-20150218</string> <string>fb-messenger-platform-20150305</string> <string>fb-messenger-api20140430</string> <string>fb-messenger-api</string>
- 系統(tǒng)分享:
activityType = com.facebook.Messenger.ShareExtension
- 未登錄下, 在應(yīng)用內(nèi)調(diào)用Messenger系統(tǒng)分享會(huì)出現(xiàn)報(bào)錯(cuò)彈窗
- Messenger系統(tǒng)分享支持url 圖片 title
- SDK分享:
- 回調(diào)和FB分享一致(可獲得成功/失敗/取消回調(diào))
-
FBSDKMessageDialog
(分享彈窗) \FBSDKShareLinkContent
(分享內(nèi)容)
- 網(wǎng)頁分享(已失效):
- fb-messenger://share?link={url}&app_id={app_id}
-
Twitter
- 白名單
<string>twitter</string>
- 系統(tǒng)分享:
activityType = com.apple.UIKit.activity.PostToTwitter
- 分享支持url 圖片 title
- iOS11之后國行手機(jī)無法測試
- SDK分享:
- 回調(diào)和FB分享一致(可獲得成功/失敗/取消回調(diào))
- 不再維護(hù)
- 網(wǎng)頁分享:
- https://twitter.com/intent/tweet?url={url}&text={title}&via={user_id}&hashtags={hash_tags}
- 有回調(diào)(通過攔截重定向
vk.com/share.php?act=success
, 可以捕捉到分享成功的回調(diào)) - 參考鏈接: https://github.com/bradvin/social-share-urls#twitter
-
Google+
- 白名單
<string>gplus</string>
- 系統(tǒng)分享:
activityType = com.google.GooglePlus.ShareExtension
- 分享支持url 圖片 title
- SDK分享: (無)
- 打開app深度鏈接分享[openURL]: (gplus:/) ---- text內(nèi)容需要UTF8編碼
- gplus:/share?text={utf-8 text}
- 網(wǎng)頁分享:
- https://plus.google.com/share?text={text}
- H5不建議使用蹂匹,發(fā)布成功發(fā)布失敗沒有重定向(域名本身沒變化, 只路徑變 不進(jìn)重定向回調(diào)中)。
- 參考鏈接: https://developers.google.com/+/web/share/
-
WhatsApp
- 白名單
<string>whatsapp</string>
- 系統(tǒng)分享:
activityType = net.whatsapp.WhatsApp.ShareExtension
- 分享支持url 圖片 title
- SDK分享: (無)
- 打開app深度鏈接分享[openURL]: (whatsapp://) ---- text內(nèi)容需要UTF8編碼
- whatsapp://send?text={utf-8 text}
- 網(wǎng)頁分享: (需翻墻)
- https://wa.me/?text={utf-8 text}
- 不建議使用H5分享凹蜈,最終也會(huì)重定向到whatsapp:// 跳轉(zhuǎn)應(yīng)用分享, 否則會(huì)是引導(dǎo)頁 {需要第三方APP支持}
-
VK
- 白名單
<string>vk</string> <string>vk-share</string> <string>vkauthorize</string>
- 系統(tǒng)分享:
activityType = com.vk.vkclient.shareextension
- 分享支持url 圖片 title
- SDK分享: (注意事項(xiàng),一定要放在FB后面)
- 打開app深度鏈接分享[openURL]: (vk://)
- 暫時(shí)找不到方法打開分享頁面, 只能打開app
- 網(wǎng)頁內(nèi)分享
//pod 'VK-ios-sdk' //注意事項(xiàng),一定要放在FB后面 //Note: if you already have FaceBook SDK added and one of this methods returns //[FBSDKDelegate ...] you can handle it -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation { [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; // 放到后面.. [VKSdk processOpenURL:url fromApplication:sourceApplication]; return YES; } //注: VKShareDialogControllerResult 分享狀態(tài)只有:取消 \ 完成 (無分享成功失\敗)
-
Line
- 白名單
<string>line</string>
- 系統(tǒng)分享:
activityType = jp.naver.line.Share
- 分享支持url 圖片 title
- SDK分享: (廢棄)
- 打開app深度鏈接分享[openURL]: (line://) 內(nèi)容需要utf-8編碼
- line://msg/<CONTENT TYPE>/<CONTENT KEY>
- line://msg/text/{utf-8 text}
- <CONTENT TYPE> = text / image /
- 網(wǎng)頁內(nèi)分享 (重定向到undefined空白頁面 - 無意義)
- https://lineit.line.me/share/ui?url={url}&text={text} [重定向: https://line.me/R/msg/text?undefined]
- 參考
-
Telegram
- 白名單
<string>tg</string>
- 系統(tǒng)分享:
activityType = ph.telegra.Telegraph.Share
- 分享支持url 圖片 title
- SDK分享: (無)
- 打開app深度鏈接分享[openURL]: (tg://) [內(nèi)容需utf-8, 支持很好]
- tg://msg?url={url}&text={utf-8 text}&to={phone_number}
- 網(wǎng)頁內(nèi)分享
- https://t.me/share/url?url={url}&text={title}&to={phone_number}
- https://telegram.me/share/url?url={url}&text={title}&to={phone_number}
-
Pinterest
- 系統(tǒng)分享:
activityType = pinterest.ShareExtension
- 分享支持url 圖片 title
- SDK分享: (無)
- 打開app深度鏈接分享[openURL]: (pinterest://) -- 暫只能打開app
- pinterest://
- 網(wǎng)頁內(nèi)分享 (text不需要utf8編碼, 否則框內(nèi)文字會(huì)顯示編碼后文字)
- https://www.pinterest.com/pin/create/link/?url={link}&media={imageURL}&description={text}
- 無回調(diào)
- 系統(tǒng)分享:
-
Instagram
- 白名單
<string>instagram-stories</string> <string>instagram</string> <string>instagram-capture</string>
-
系統(tǒng)分享:
activityType = com.burbn.instagram.shareextension
- 圖片
SDK分享: (無)
-
打開app深度鏈接分享[openURL]: (instagram://) 暫只能打開app https://www.instagram.com/developer/mobile-sharing/iphone-hooks/
- 方式一(直接分享 - OpenURL方式):
NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"]; if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) { // Assign background image asset and attribution link URL to pasteboard NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.shareImageUrl]]; NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : data, @"com.instagram.sharedSticker.contentURL" : self.shareURL}]; NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]}; // This call is iOS 10+, can use 'setItems' depending on what versions you support [[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions]; [[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:^(BOOL success) { if (success) { [self leaveCurrentAPPToThirdApp]; } }]; }
- 方式二(間接分享 - 再彈出系統(tǒng)分享選擇): 分享igo文件的形式,彈起類似系統(tǒng)更多分享彈窗,拷貝到Instagram [速賣通 ins分享方式]
NSString *documentDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; // *.igo is exclusive to instagram NSString *saveImagePath = [documentDirectory stringByAppendingPathComponent:@"Image.igo"]; // NSData *imageData = UIImagePNGRepresentation(filteredImage); [data writeToFile:saveImagePath atomically:YES]; NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath]; _docController=[[UIDocumentInteractionController alloc]init]; _docController.delegate=self; _docController.UTI=@"com.instagram.photo"; [_docController setURL:imageURL]; _docController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:@"#yourHashTagGoesHere",@"InstagramCaption", nil]; [_docController presentOpenInMenuFromRect:CGRectZero inView:[UIViewController bgl_currentViewController].view animated:YES];
- 方式三(間接分享 - 再彈出系統(tǒng)分享選擇): ps: 只能純分享UIImage , Text或者URL不能分享, 分享則沒有Ins這個(gè)Ativity
網(wǎng)頁內(nèi)分享 (無)
.
.
.
.
.
.
沒裝三方客戶端不能實(shí)現(xiàn)分享(無網(wǎng)頁分享 ): Instagram[無] / Line [重定向跳轉(zhuǎn)空白頁] / WhatsApp[重定向引導(dǎo)] / Messenger[無] / Telegram [跳轉(zhuǎn)引導(dǎo)]