Facebook Messenger 无法在 iOS 9 和 Swift 中打开 URL

Facebook Messenger can't open URL in iOS 9 with Swift

我在 iOS 9 上使用 Facebook Messenger SDK,但无法共享。即使我在我的 iPhone 上安装了 Facebook Messenger,它也好像不存在一样。

以下行将 return0: FBSDKMessengerSharer.messengerPlatformCapabilities()

我想提一下,在 iOS 8.

上一切正常

回答我自己的问题:URL 方案在 iOS 9 中发生了一些变化,您必须添加 Facebook Messenger 的 URL 方案,类似于 [=15] =] 为您的应用程序。

您可以在此处找到更多详细信息:

请在您的 Appdelegate 中添加这些行 Class

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

        return true
    }



    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

     return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
    }

 func applicationDidBecomeActive(application: UIApplication) {
        FBSDKAppEvents.activateApp()


    }

并确保你是否添加了这些信息.plist

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

如果您使用任何可以将应用切换到 Facebook 应用的 Facebook 对话框(例如,登录、分享、应用邀请等),您将需要更新应用的 plist 以处理对 canOpenURL 描述的更改在 https://developer.apple.com/videos/wwdc/2015/?id=703.

如果您使用 iOS SDK 9.0 重新编译,如果您使用的是 SDK v4.5 或更早版本,请将以下内容添加到应用程序的 plist 中:

<key>LSApplicationQueriesSchemes</key> <array> <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>fbapi20160328</string> <string>fbauth</string> <string>fbauth2</string> <string>fb-messenger-api20140430</string> </array>

如果您使用的是早于 v4.6 版本的 FBSDKMessengerShareKit,还请添加

<string>fb-messenger-platform-20150128</string> <string>fb-messenger-platform-20150218</string> <string>fb-messenger-platform-20150305</string>

如果您使用v4.6.0或更高版本的SDK,您只需添加:

<key>LSApplicationQueriesSchemes</key> <array>      <string>fbapi</string>      <string>fb-messenger-api</string>       <string>fbauth2</string>        <string>fbshareextension</string> </array>

这将允许 FacebookSDK 集成正确识别已安装的 Facebook 应用程序以执行应用程序切换。如果您不使用 iOS SDK 9.0 重新编译,您的应用将被限制为 50 个不同的方案(之后调用 canOpenURL return 否)。