38

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

-canOpenURL:URL 失败:“fbauth://authorize/?client_id=... 错误:“此应用不允许查询方案 fbauth”

你能帮我吗?

4

4 回答 4

32

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

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth</string>
    </array>
于 2015-06-10T19:26:31.827 回答
28

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

  1. 下载适用于 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}}
  1. 将 Facebook 应用程序列入白名单

如果您使用任何可以执行应用程序切换到 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>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
</array>

如果您使用的 FBSDKMessengerShareKit 来自 v4.6 版本之前的版本,请同时添加

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

于 2015-09-10T20:42:01.497 回答
5

按照此链接查看 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>
于 2015-10-12T09:26:46.270 回答
0

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框架,如

=>Bolts.framework
=>FBSDKCoreKit.framework
=>FBSDKLoginKit.framework
=>FBSDKShareKit.framework
于 2015-10-03T05:54:56.467 回答