繁体   English   中英

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

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

我在iOS 9上使用Facebook Messenger SDK,但共享无效。 即使我在我的iPhone上安装了Facebook Messenger,它就像它不会那样。

以下行将返回0:FBSDKMessengerSharer.messengerPlatformCapabilities()

我想提一下在iOS 8上一切正常。

如果您使用可以执行应用程序切换到Facebook应用程序的任何Facebook对话框(例如,登录,共享,应用程序邀请等),您将需要更新应用程序的plist以处理对https://中的 canOpenURL描述的更改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个不同的方案(调用tocanOpenURL之后返回NO)。

回答我自己的问题:在iOS 9中,URL方案的内容发生了一些变化,你必须为你的应用添加一个“白名单”的Facebook Messenger的URL方案。

您可以在此处找到更多详细信息: iOS 9无法使用URL SCHEME打开Instagram应用程序

请在Appdelegate类中添加这些行

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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM