swift 2解析facebookSDK ios9

kal*_*fun 37 parse-platform facebook-sdk-4.0 swift2

我想通过Facebook登录用户.在以前版本的swift 1.2中,一切都运行良好,但迁移后我似乎无法通过我的FB帐户登录,我仍然收到错误说:

-canOpenURL:URL失败:"fbauth:// authorize /?client_id = ... error:"此应用程序不允许查询方案fbauth"

你能帮帮我吗?

Mar*_*ham 31

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

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth</string>
    </array>
Run Code Online (Sandbox Code Playgroud)

  • 得到同样的问题,把它添加到Info.plist后我得到了这个:-canOpenURL:URL失败:"fbauth:// authorize /?client_id = ..." - 错误:"(null)",好像FBSDK有有问题. (10认同)
  • 不幸的是,它仍然是同样的错误 (2认同)

mog*_*oli 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编译您的应用程序,您将受到App Transport Security的影响.目前,您需要将以下内容添加到应用程序的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>
Run Code Online (Sandbox Code Playgroud)

或者你会遇到如下错误:

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}}
Run Code Online (Sandbox Code Playgroud)
  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>
Run Code Online (Sandbox Code Playgroud)

如果您从早于v4.6版本的版本使用FBSDKMessengerShareKit,也请添加

<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
Run Code Online (Sandbox Code Playgroud)

如果您使用的是SDK的v4.6.0,则只需添加:

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbapi</string>
        <string>fb-messenger-api</string>
        <string>fbauth2</string>
        <string>fbshareextension</string>
</array>
Run Code Online (Sandbox Code Playgroud)

这将允许FacebookSDK集成正确识别已安装的Facebook应用程序以执行应用程序切换.如果您没有使用iOS SDK 9.0重新编译,您的应用程序将限制为50个不同的方案(之后调用canOpenURL返回NO).


小智 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"
Run Code Online (Sandbox Code Playgroud)

对于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>
Run Code Online (Sandbox Code Playgroud)

对于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>
Run Code Online (Sandbox Code Playgroud)