【发布时间】:2017-06-24 07:21:00
【问题描述】:
我尝试了很多方法来实现这一点,但都失败了。
我必须在 facebook 上使用 URL 共享信息,当单击该 url 时,它将重定向到我的应用程序的特定页面。
步骤#1
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: linkUrl) as URL!
content.contentTitle = "Test"
content.quote = "game"
content.contentDescription = "This is a test game to test Fb share functionality"
content.imageURL = NSURL(string: imgUrl) as URL!
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.native
dialog.fromViewController = vc
dialog.shareContent = content
// 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 = FBSDKShareDialogMode.feedBrowser
}
dialog.show()
它正在工作并成功分享帖子。当我点击链接时,它正在重定向到应用程序,没有太多信息可以重定向到特定的 ViewController。
步骤#2
let properties = [
"fb:app_id": "Fb_id",
"og:type": "article",
"og:title": "Test",
"og:description": "This is a test game to test Fb share functionality",
"og:image" : urlImg,
"og:url" : linkUrl,
]
let object : FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject.init(properties: properties)
// Create an action
let action : FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
action.actionType = "news.publishes"
action.setObject(object, forKey: "article")
// Create the content
let content : FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "article"
FBSDKShareDialog.show(from: vc, with: content, delegate: nil)
我在这里使用 Open Graph 发布并成功发布了信息。但是点击链接时不会重定向到我的应用程序。
注意:
我没有网络应用程序。
我的目标是分享带有应用链接的帖子。单击该链接时,它将打开应用程序并在安装了应用程序时重定向到特定页面,否则重定向到 AppStore。那么 link 格式应该是什么,或者我如何构建链接来实现此功能?
请帮忙。
提前致谢
【问题讨论】:
-
如果我在笔记本电脑或 Android 手机上看到共享,会发生什么?
-
嗨 WizKid,我认为如果安装了应用程序,它将重定向到笔记本电脑和 android 中的相应应用程序商店,然后打开应用程序,否则重定向到播放商店
-
嗨 @SailendraKumarDhal 在第 1 步中,您从哪里获得 linkUrl?
标签: ios swift facebook facebook-opengraph deep-linking