如何在swift 3中实现iOS应用程序链接Facebook功能? [英] How to implement iOS app link Facebook functionality in swift 3?
问题描述
我必须在Facebook上与网址分享信息,点击网址后,将重定向到我的应用的特定页面。
步骤#1
让内容:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL (string:linkUrl)作为URL!
content.contentTitle =Test
content.quote =game
content.contentDescription =这是一个测试游戏来测试Fb共享功能
content.imageURL = NSURL(string:imgUrl)作为URL!
let对话框:FBSDKShareDialog = FBSDKShareDialog()
dialog.mode = FBSDKShareDialogMode.native
dialog.fromViewController = vc
dialog.shareContent = content
/ /如果没有在CanShow调用之前设置,canShow总是返回YES
如果!dialog.canShow(){
//当没有FB应用程序
时,回退演示文稿dialog.mode = FBSDKShareDialogMode.feedBrowser
}
dialog.show()
正在工作并成功分享这个职位。当我点击链接时,它正在重定向到应用程序,没有太多的信息重定向到特定的ViewController。
步骤#2
let properties = [
fb:app_id:Fb_id,
og:type:article,
og:title:Test,
og:description:这是一个测试游戏来测试Fb共享功能,
og:image:urlImg,
og:url:linkUrl,
]
let对象:FBSDKShareOpenGraphObject = FBSDKShareOpenGraphObject.init(properties:properties)
//创建一个动作
让动作:FBSDKShareOpenGraphAction = FBSDKShareOpenGraphAction()
action.actionType =news.publishes
action.setObject(object,forKey:article)
//创建内容
let content:FBSDKShareOpenGraphContent = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName =article
FBSDKShareDialog.show(from:vc,with:content,代表:nil)
这里我使用Open Graph发布并成功发布信息。但是,当点击链接时,不要重定向到我的应用程序。
注意:
我没有Web应用程序。
我的目标是通过应用链接分享一篇文章。当点击该链接时,它会打开应用程序,并重定向到特定页面,如果安装了应用程序,否则重定向到AppStore。那么应该是什么样的链接格式,或者如何建立链接来实现这个功能?
请帮忙。
提前感谢
是的,我通过
参考文献: https://developers.facebook.com/docs/applinks
https://developers.facebook.com/docs/applinks/ios
谢谢...
I have tried many ways to achieve this but failed.
I have to share info on facebook with a URL and when clicked on the url, it will redirect to my app's specific page.
step# 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()
It is working and successfully sharing the post. When I clicked on the link, it is redirecting to the app, not much info to redirect to a particular ViewController.
Step# 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)
Here I am using Open Graph to post and successfully posted the Info. But con't redirecting to my app when clicked the link.
NB:
I don't have web Application.
My goal is to share a post with a app link. When clicked on that link it will open the app and redirect to a specific page if app is installed, otherwise redirect to the AppStore. So what should be the link format or how can I build the link to achieve this functionality?
Please help.
Thanks in advance
Yes, I achieved this functionality by setting up the metadata in the server end.
References: https://developers.facebook.com/docs/applinks
https://developers.facebook.com/docs/applinks/ios
Thanks...
这篇关于如何在swift 3中实现iOS应用程序链接Facebook功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!