swift 2 解析facebookSDK ios9

Posted

技术标签:

【中文标题】swift 2 解析facebookSDK ios9【英文标题】:swift 2 parse facebookSDK ios9 【发布时间】:2015-06-09 15:36:59 【问题描述】:

我正在尝试通过 Facebook 登录用户。在之前版本的 swift 1.2 中,一切正常,但迁移后我似乎无法通过我的 FB 帐户登录,我仍然收到错误消息:

-canOpenURL: failed for URL: "fbauth://authorize/?client_id=... error: "This app is not allowed to query for scheme fbauth"

你能帮帮我吗?

【问题讨论】:

为什么会有这些减分? 没有理由吗? ios9 对查询方案添加了一些限制。我相信这是出于隐私问题 - 应用程序可以看到您在手机上安装的内容,即使它们无意为给定方案启动 url。 所以在更新这些框架之前,我不可能在 iOS9 上继续开发? 【参考方案1】:

从 WWDC 2015“隐私和您的应用”视频中,将以下内容添加到您的 info.plist 文件中:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth</string>
    </array>

【讨论】:

尝试以下方法,因为它对我有用。在 Xcode 7 中为 iOS 9 创建一个新的 Swift 2.0 应用程序。在 AppDelegate.swift 文件中,将 let sharedApplication = UIApplication.sharedApplication(); let isFacebookAuthorized = sharedApplication.canOpenURL(NSURL(fileURLWithPath: "fbauth://authorize")); 添加到 didFinishLaunchingWithOptions 中。构建并运行。您应该得到“不允许查询方案”错误。接下来,打开 Info.plist 作为源代码,并将我原始回复中的代码插入到 &lt;/dict&gt; 前面的文件中。重建并运行。您应该不会再收到该错误。 我现在已经回到 Xcode 6,等待 Parse 和 FBSDK 真正发布一个可以在 iOS9 上运行的新版本,并且还使用 bitcode 构建了库 一个工作代码示例可以在这里找到:github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example 遇到了同样的问题,将其添加到 Info.plist 后,我​​得到了这个:-canOpenURL: failed for URL: "fbauth://authorize/?client_id=..." - error: "(null )",好像FBSDK有问题。 @nebiros 据我所知错误:“(null)”仅当请求的应用程序在白名单中但未安装在系统上时才会显示此错误。【参考方案2】:

我建议按照 Facebook 的说明为 iOS 9 准备一个应用程序: https://developers.facebook.com/docs/ios/ios9

    下载适用于 iOS 的最新 Facebook SDK

为您的应用下载适当版本的 Facebook SDK。

v4.x - 推荐。 v3.24.0 - 仅当您尚未迁移到 SDK 的 v4.x 时。 2. 网络请求的 Facebook 服务器白名单

如果您使用 iOS SDK 9.0 编译您的应用程序,您将受到应用程序传输安全性的影响。目前,您需要通过将以下内容添加到应用程序的 plist 中来将应用程序中的 Facebook 域列入白名单:

<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>

否则你会遇到如下错误:

NSUnderlyingError=0x7f88f9436eb0 Error Domain=kCFErrorDomainCFNetwork
Code=-1200 "An SSL error has occurred and a secure connection to
the server cannot be made." UserInfo=NSErrorFailingURLStringKey=
https://graph.facebook.com/v2.4, NSLocalizedRecoverySuggestion=
Would you like to connect to the server anyway?,
_kCFNetworkCFStreamSSLErrorOriginalValue=-9802,
kCFStreamPropertySSLPeerCertificates=<CFArray 0x7f88f9536e00
[0x10719f7c0]>type = immutable, count = 2, values = (
0 : <cert(0x7f88f963f840) s: *.facebook.com (http://facebook.com/)
i: DigiCert High Assurance CA-3>
1 : <cert(0x7f88f96444c0) s: DigiCert High Assurance CA-3 i:
DigiCert High Assurance EV Root CA> ), 
_kCFStreamPropertySSLClientCertificateState=0,
kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x7f88f9644d10>,
NSLocalizedDescription=An SSL error has occurred and a secure connection
to the server cannot be made.,_kCFStreamErrorDomainKey=3,
NSErrorFailingURLKey=https://graph.facebook.com/v2.4,
_kCFStreamErrorCodeKey=-9802
    将 Facebook 应用列入白名单

如果您使用任何可以执行应用程序切换到 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>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)。

【讨论】:

我对这个回复中的akamaihd.net 部分感到好奇,因为它似乎与 facebook 无关,并在谷歌上搜索并发现了一大堆与恶意软件和相关问题相关的信息。它似乎是 facebook 使用的 CDN,但我们确定这是必需的吗? 这个答案真的很棒,几乎涵盖了所有内容。【参考方案3】:

点击此链接可查看 Facebook 推荐的 iOS 9 更新 https://developers.facebook.com/docs/ios/ios9

为了修复这个特定的错误

-canOpenURL: failed for URL: "fbauth://authorize/?client_id=... error: "This app is not allowed to query for scheme fbauth"

对于 Facebook SDK 4.6+ 版,转到您的 info.plist 文件并添加以下内容:

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

对于 4.5 或更早版本:

<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>
</array>

【讨论】:

我正在运行 <string>fb-messenger-platform-20150128</string>。换句话说,从我的错误消息中添加确切的方案,即"This app is not allowed to query for scheme fb-messenger-platform-20150218"【参考方案4】:

1] 在 Developer.facebook 中进行身份验证并生成 Facebook Id

2] 设置位码:从构建设置中否

3] 设置 Plist 文件

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb460481580805052</string>
        </array>
    </dict>
</array>

<key>FacebookAppID</key>
<string>460481580805052</string>

<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </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>
    </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>

4] 下载 4 Sdk Framework like

=>Bolts.framework
=>FBSDKCoreKit.framework
=>FBSDKLoginKit.framework
=>FBSDKShareKit.framework

【讨论】:

以上是关于swift 2 解析facebookSDK ios9的主要内容,如果未能解决你的问题,请参考以下文章

将 FacebookSDK 导入 Swift 应用程序

FacebookSDK(4.7) 自定义登录 UI 按钮 - Swift 2.0

Facebook SDK 4.0 IOS Swift 以编程方式注销用户

Swift - 立即解析 Facebook 登录默认为用户取消登录

在 iOS 上将 FBConnect SDK 升级到 FacebookSDK 3.0 时缺少 FBRequestDelegate

ios swift 2 解析中的流式音频