【问题标题】:Facebook Messenger can't open URL in iOS 9 with SwiftFacebook Messenger 无法使用 Swift 在 iOS 9 中打开 URL
【发布时间】:2015-10-26 11:13:04
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios facebook swift ios9 messenger


    【解决方案1】:

    如果您使用任何可以执行应用程序切换到 Facebook 应用程序的 Facebook 对话框(例如,登录、分享、应用程序邀请等),您将需要更新应用程序的 plist 以处理对@中描述的 canOpenURL 的更改987654321@.

    如果您使用 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 之后返回 NO)。

    【讨论】:

      【解决方案2】:

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

      您可以在此处找到更多详细信息:iOS 9 not opening Instagram app with URL SCHEME

      【讨论】:

        【解决方案3】:

        请在您的 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>
        

        【讨论】:

          猜你喜欢
          • 2019-04-12
          • 2014-09-22
          • 2015-11-03
          • 2015-12-18
          • 2019-03-10
          • 1970-01-01
          相关资源
          最近更新 更多