【问题标题】:FBSDK secure network request failed iOS9FBSDK安全网络请求失败iOS9
【发布时间】:2015-12-18 07:53:02
【问题描述】:

我们在模拟器中遇到了 App Transport Security 错误(Xcode 7 在 OSX 10.10.5 上运行)。我们为 iOS9 实施了 FB 指南。

调用的FB graph api是基于SDK v.3.24的。

在将所需的应用程序传输安全异常插入应用程序 info.plist 文件后,我们添加了 Facebook SDK,使用 Bit 成功编译。

这些错误看起来像 Facebook 文档中缺少 ATS info.plist 配置, 一世。 e.:

NSURLSession/NSURLConnection HTTP 加载失败 (kCFStreamErrorDomainSSL, -9802)
2015-09-21 15:25:20.862 flirtop [41983:2110078] FBSDKLog:警告:FBSDK 安全网络请求失败。请验证您已为应用程序传输安全兼容性配置您的应用程序,如 https://developers.facebook.com/docs/ios/ios9 所述
2015-09-21 15:25:21.131 flirtop [41983:2110592] NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9802)
2015-09-21 15:25:21.132 flirtop [41983:2110078] FBSDKLog:警告:FBSDK 安全网络请求失败。请验证您已为应用程序传输安全兼容性配置您的应用程序,如 https://developers.facebook.com/docs/ios/ios9 所述
2015-09-21 15:25:21.135 flirtop[41983:2110078] 错误域=NSURLErrorDomain 代码=-1200 “发生 SSL 错误,无法与服务器建立安全连接。” UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=您是否仍要连接到服务器?, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, NSErrorPeerCertificateChainKey={type = immutable, count = 2, values = (
    0:
    1:
)}, NSUnderlyingError=0x7fec5d300b40 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 “发生 SSL 错误,无法与服务器建立安全连接。” UserInfo={NSErrorFailingURLStringKey=https://graph.facebook.com/v2.4, NSLocalizedRecoverySuggestion=你还想连接到服务器吗?, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, kCFStreamPropertySSLPeerCertificates={type = immutable, count = 2, values = (
    0:
    1:
)}, _kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=, NSLocalizedDescription=发生 SSL 错误,无法与服务器建立安全连接。, _kCFStreamErrorDomainKey=3, NSErrorFailingURLKey=https://graph.facebook.com/v2.4, _kCFStreamErrorCodeKey =-9802}}, NSLocalizedDescription=发生 SSL 错误,无法与服务器建立安全连接。, --- SNIP --

我们的 plist 省略了 App Id,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>com.fwlab.$(PRODUCT_NAME:rfc1034identifier)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>OMITTED</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>OMITTED</string>
    <key>FacebookDisplayName</key>
    <string>Flirtop</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>graph.facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>fbcdn.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>akamaihd.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    <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>fbauth</string>
        <string>fbauth2</string>
        <string>fb-messenger-api20140430</string>
        <string>fb-messenger-platform-20150128</string>
        <string>fb-messenger-platform-20150218</string>
        <string>fb-messenger-platform-20150305</string>
    </array>
</dict>
</plist>

【问题讨论】:

  • 既然您已经拥有facebook.com 并包含子域on,您是否尝试过简单地删除graph.facebook.com 看看会发生什么?
  • 是的,这不是问题。

标签: ios facebook ssl sdk ios9


【解决方案1】:

其他选项是“允许任意负载”,通过将NSAllowsArbitraryLoads 键设置为YES

一个可选的布尔值,当设置为 YES 时,禁用 App 您未重新启用的任何域的传输安全性 (ATS) 使用异常域字典进行 ATS。

更多信息here>>

【讨论】:

    【解决方案2】:

    将此添加到您的 Info.plist 文件中,错误就会消失。如果您不理解 XML 代码,请参阅下面的屏幕截图。

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>fbcdn.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
            <key>akamaihd.net</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
        </dict>
    </dict>
    

    Xcode 的屏幕截图可能比纯 XML 更能帮助您:

    【讨论】:

    • 谢谢,小伙子。很快就做到了。
    • 不适合我。我正在尝试使用 Graph API 获取用户详细信息。
    【解决方案3】:

    只需点击以下链接,您需要在 info.plist 中进行一些更新

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

    【讨论】:

      【解决方案4】:

      解决了。 复制到 App 包中的 info.plist 不是正确的。 这可以在没有 graph.facebook.com 条目的情况下工作,这不是必需的。

      当我尝试使用 Facebook 登录时很明显,它抱怨 url fbauth2 不在 info.plist 文件中。

      顺便说一下,Info.plist 的正确结尾部分如下,其中包括正确的完整 Facebook SDK 设置。 NSExceptionRequiresForwardSecrecy = False 足以让 FB graph api 工作。

      由于 FB 服务器不在我的控制之下,可能我应该使用 NSThirdPartyException,但是以下设置有效。

      -- SNIP --
      <key>UIMainStoryboardFile</key>
          <string>Main</string>
          <key>UIRequiredDeviceCapabilities</key>
          <array>
              <string>armv7</string>
          </array>
          <key>UIStatusBarTintParameters</key>
          <dict>
              <key>UINavigationBar</key>
              <dict>
                  <key>Style</key>
                  <string>UIBarStyleDefault</string>
                  <key>Translucent</key>
                  <false/>
              </dict>
          </dict>
          <key>UISupportedInterfaceOrientations</key>
          <array>
              <string>UIInterfaceOrientationPortrait</string>
              <string>UIInterfaceOrientationLandscapeLeft</string>
              <string>UIInterfaceOrientationLandscapeRight</string>
              <string>UIInterfaceOrientationPortraitUpsideDown</string>
          </array>
          <key>UISupportedInterfaceOrientations~ipad</key>
          <array>
              <string>UIInterfaceOrientationPortrait</string>
              <string>UIInterfaceOrientationPortraitUpsideDown</string>
              <string>UIInterfaceOrientationLandscapeLeft</string>
              <string>UIInterfaceOrientationLandscapeRight</string>
          </array>
          <key>NSAppTransportSecurity</key>
          <dict>
              <key>NSExceptionDomains</key>
              <dict>
                  <key>facebook.com</key>
                  <dict>
                      <key>NSIncludesSubdomains</key>
                      <true/>
                      <key>NSExceptionRequiresForwardSecrecy</key>
                      <false/>
                  </dict>
                  <key>fbcdn.net</key>
                  <dict>
                      <key>NSIncludesSubdomains</key>
                      <true/>
                      <key>NSExceptionRequiresForwardSecrecy</key>
                      <false/>
                  </dict>
                  <key>akamaihd.net</key>
                  <dict>
                      <key>NSIncludesSubdomains</key>
                      <true/>
                      <key>NSExceptionRequiresForwardSecrecy</key>
                      <false/>
                  </dict>
              </dict>
          </dict>
          <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>fbauth</string>
              <string>fbauth2</string>
              <string>fb-messenger-api20140430</string>
              <string>fb-messenger-platform-20150128</string>
              <string>fb-messenger-platform-20150218</string>
              <string>fb-messenger-platform-20150305</string>
          </array>
      </dict>
      </plist>
      

      【讨论】:

      • 我有包含 fbauth2 的 plist 文件;应用程序正确登录和注销;但是我仍然收到以下error: [4102:149576] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"知道为什么吗?
      • 这很可能是一个完全不相关的问题。在我的情况下,我确实收到了一个错误(“发生了 SSL 错误,无法建立与服务器的安全连接。”),而不是空错误。在调查该问题不是关于分配问题后,如果您仍然有问题,您应该记录您的段落并打开另一个问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 2019-01-06
      • 2018-06-11
      • 2022-01-12
      • 2020-11-11
      相关资源
      最近更新 更多