【问题标题】:How to implement iOS app link Facebook functionality in swift 3?如何在 swift 3 中实现 iOS 应用链接 Facebook 功能?
【发布时间】: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


【解决方案1】:

是的,我通过在服务器端设置元数据实现了这个功能。

参考:https://developers.facebook.com/docs/applinks

https://developers.facebook.com/docs/applinks/ios

谢谢...

【讨论】:

    【解决方案2】:

    我设法使用 Branch.io 实现了相同的结果。这是一个非常强大的应用程序路由 SDK,他们的控制台实际上以非常直观和易于理解的方式指导您完成路由方案。

    它的工作方式是根据您在仪表板中设置的内容动态创建具有某些重定向功能的网页。然后,您可以使用生成的网页在 Facebook 或其他任何地方分享它。

    您可以通过以下方式集成它:

    1. 创建帐户here

    2. 安装并链接 SDK (pod 'Branch')

    3. 使用 Branch 的仪表板设置路由机制(它具有指导性且非常简单,您只需填写下面的分支)。您可以随时更改图表的外观(例如,如果您希望始终出现在网站上)

    1. 在您的应用中初始化共享数据

      let branchUniversalObject: BranchUniversalObject = BranchUniversalObject(canonicalIdentifier: "any ID here")    // just for tracking count and analytics
      branchUniversalObject.title = "some title"    // This will appear as the shared content's title
      branchUniversalObject.contentDescription = "some description"    // This will appear as the shared content's description
      branchUniversalObject.imageUrl = "www.example.com/test.png"
      branchUniversalObject.addMetadataKey("uid", value: self.userId)
      branchUniversalObject.addMetadataKey("otherInfo", value: self.otherInfo)
      
    2. 生成链接并在 Facebook 上分享链接

      let linkProperties = BranchLinkProperties()
      linkProperties.channel = "Facebook"
      linkProperties.feature = "Share"
      
      // generate link     
      branchUniversalObject.getShortUrl(with: linkProperties, andCallback: { (shareURL, error) in
          if error != nil {
              // handle error
          }
      
      
          // init Facebook share data
          let content = FBSDKShareLinkContent()
          content.contentTitle = "Some title"
          content.contentURL = URL(string: shareURL)    // this URL handles the redirecting according to your dashboard's settings
          content.contentDescription = "Some description"
          content.imageURL = URL(string: "www.example.com/test.png")
      
          // create Facebook share dialog    
          let dialog = FBSDKShareDialog()
          dialog.fromViewController = self
          dialog.delegate = self
          dialog.shareContent = content
          dialog.mode = .automatic
          if dialog.canShow() {
              dialog.show()
          }
      
      }) 
      

    【讨论】:

      【解决方案3】:

      使用通用链接。如果您想使用通用链接实现这样的目标是一个好主意。如果应用已安装,您可以重定向到应用中的特定页面,否则它将导航到应用商店。

      如果您不知道,以下是如何实现通用链接:

      Set up universal links - Raywenderlich

      Universal links - Appsflyer

      注意:如果这不是您要查找的内容,请忽略此内容

      【讨论】:

      • 嗨 Sivajee 感谢您的回答。是的,我已经尝试过通用链接功能。在 web 端设置 apple-app-site-association 文件有点复杂。而且这里没有网络应用。
      • 是的,我该如何构建自定义 url?任何建议
      • 是的。请点击此链接code.tutsplus.com/tutorials/…
      • 此链接也可能对您有用:stackoverflow.com/questions/33821603/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多