与FBSDKShareLinkContent
共享FBSDKShareDialog
在iOS 8中运行良好,但无法在iOS 9设备上共享imageURL
,contentTitle
,contentDescription
。
该应用程序是使用iOS 9 SDK,Xcode 7,Facebook SDK 4.7.0构建的,Preparing Your Apps for iOS9中提到的所有操作都已完成。该应用程序目前在App Store中不可用,Facebook应用程序处于开发模式。
呈现对话框的代码很常见(Swift 2.0):
let content = FBSDKShareLinkContent()
content.contentURL = <URL to the app in the App Store>
content.imageURL = <valid image URL>
content.contentTitle = <some title>
content.contentDescription = <some descr>
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = viewController
shareDialog.shareContent = content
shareDialog.delegate = self
if !shareDialog.canShow() {
print("cannot show native share dialog")
}
shareDialog.show()
在iOS 9上,Facebook SDK提供原生对话框,没有图像,标题和描述:
在显示对话框时,当在iOS 9设备上安装FB应用程序时,会出现错误,通过向Info.plist添加相应的URL解决此问题无法解决问题。它只是不再出现的日志语句。
-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"
在iOS 8上,对话框通过FB应用程序显示,或者在未安装FB应用程序时打开应用程序内部的Safari vc。
为了比较起见,相同的代码适用于iOS 8设备:
更新
虽然@rednuht's answer below解决了最初的问题,但值得注意的是AppStore URL-specific case pointed out by @sophie-fader
答案 0 :(得分:58)
我遇到了同样的问题,我正在使用的解决方法是将共享对话框模式设置为使用本机应用。
我正在使用Obj-C,但在Swift中几乎应该是相同的:
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = viewController;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeNative; // if you don't set this before canShow call, canShow would always return YES
if (![dialog canShow]) {
// fallback presentation when there is no FB app
dialog.mode = FBSDKShareDialogModeFeedBrowser;
}
[dialog show];
在iOS 9中,用户可以获得应用切换对话框,但效果很好。还有FBSDKShareDialogModeWeb
,它没有应用切换对话框,但也没有显示图像。
默认为FBSDKShareDialogModeAutomatic
,会选择FBSDKShareDialogModeShareSheet
,这就是您所看到的。
UPDATE :这是iOS9中可用对话框模式的行为:
FBSDKShareDialogModeAutomatic
:使用ShareSheet,这是OP案例FBSDKShareDialogModeShareSheet
:ditto FBSDKShareDialogModeNative
:如果用户安装了FB应用程序,则无效,否则无效。提供app-switch对话框。FBSDKShareDialogModeBrowser
:无图像分享FBSDKShareDialogModeWeb
:无图像分享FBSDKShareDialogModeFeedBrowser
:按预期工作 FBSDKShareDialogModeFeedWeb
:按预期工作 “浏览器”打开Safari全屏,“Web”打开webview对话框。
我会选择iOS9的最后两个选项和iOS8的自动选项。
答案 1 :(得分:10)
问题的解决方法是将“共享对话”模式设置为使用本机应用。在iOS9中,swift 2.0
对于第一个问题:Facebook分享内容可以与iTunes共享内容描述以外的网址。如果共享iTunes网址,则不会分享我们的说明。
下一篇:我遇到了同样的问题,FB Share按钮点击将我重定向到浏览器,我使用的解决方法是将Share Dialog模式设置为使用本机应用程序。
如果您要共享的URL是iTunes App Store URL,则会一致地发生这种情况。将URL更改为任何其他网站解决了该问题。 https://developers.facebook.com/docs/sharing/ios&#34;
注意:如果您的应用分享指向iTunes或Google Play商店的链接,我们不会发布您在共享中指定的任何图像或说明。相反,我们会直接使用Webcrawler发布我们从应用商店中获取的一些应用信息。这可能不包括图像。要预览iTunes或Google Play的链接共享,请在URL调试器中输入您的URL。&#34;
func shareFB(sender: AnyObject){
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "//URL other then iTunes/AppStore")
content.contentTitle = “MyApp”
content.contentDescription = “//Desc“
content.imageURL = NSURL(string:“//Image URL”)
let dialog : FBSDKShareDialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.Native
// if you don't set this before canShow call, canShow would always return YES
if !dialog.canShow() {
// fallback presentation when there is no FB app
dialog.mode = FBSDKShareDialogModeFeedBrowser
}
dialog.show()
}
答案 2 :(得分:7)
删除错误消息:
-canOpenURL: failed for URL: "fbapi20150629:/" - error: "This app is not allowed to query for scheme fbapi20150629"
,您可以在项目的info.plist中的<key>LSApplicationQueriesSchemes</key>
数组中添加以下行:
<string>fbapi20150629</string>
答案 3 :(得分:2)
您的应用中的Facebook分享对话框,标题,说明和&amp;图像:
dialog.mode = FBSDKShareDialogMode.ShareSheet //未尝试
or
//Working for me:
let linkcontent: FBSDKShareLinkContent = FBSDKShareLinkContent()
linkcontent.contentURL = videoURL
// linkcontent.contentDescription = videoDesc
// linkcontent.contentTitle = videoTitle
// linkcontent.imageURL = imageURL
FBSDKShareDialog.showFromViewController(self, withContent: linkcontent, delegate: self)
meta http-equiv =&#34; content-type&#34;含量=&#34; text / html的;字符集= UTF-8&#34;&GT; title&gt; MY SHRED URL TITLE 元内容=&#39;&#34; + imageUrl +&#34;&#39;属性=&#39; OG:图像&#39; /&GT;
答案 4 :(得分:2)
如果您正在分享您是网站管理员的网站,那么最好的办法就是共享contentURL
。然后按照此处的信息将Open Graph标记添加到HTML文件中:https://developers.facebook.com/docs/sharing/webmasters
Facebook将从网页上抓取信息,并从那里填充所有字段。要确保值看起来正确,请运行调试器:
https://developers.facebook.com/tools/debug/
在该页面上,您实际上可以再次强制刮取,这将被缓存。
答案 5 :(得分:2)
以下代码在各种情况下对我来说都很有魅力:
'method to sort values based on carriers defined in a custom list
'carriers are ordered by pickup times
'
Sub CustomSort()
ActiveWorkbook.Worksheets("Outbound Work Status").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Outbound Work Status").Sort.SortFields.Add Key:=Range("D:D"), _
SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"Truck,Collect,Holland,LME,YRC", DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Outbound Work Status").Sort
.SetRange Range("A3:Z9999")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
答案 6 :(得分:0)
如果我们将FBSDKShareLinkContent
contentURL设为空,则会分享Facebook标题。
例如:
content.contentURL = [[NSURL alloc] initWithString:@"http://"];
答案 7 :(得分:0)
{{1}}
答案 8 :(得分:0)
对于 Swift >= 5.0,您可以按照下面的教程...
Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.