swift 2parsingfacebookSDK ios9

我正在尝试通过Facebooklogin用户。 在以前的版本的迅速1.2一切正常,但移植后,我似乎无法通过我的FB帐户login我仍然得到错误说:

-canOpenURL:URL失败:“fbauth:// authorize /?client_id = …错误:”此应用程序不允许查询scheme fbauth“

你能帮我吗?

我build议按照Facebook的指示准备iOS 9应用程序: https : //developers.facebook.com/docs/ios/ios9

  1. 下载适用于iOS的最新Facebook SDK

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

v4.x – build议。 v3.24.0 – 只有当您还没有迁移到SDK的v4.x。 2.networking请求的白名单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对话框(例如,login,共享,应用程序邀请等),您将需要更新您的应用程序的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> 

如果您使用的是早于v4.6发行版的FBSDKMessengerShareKit,也可以添加

 <string>fb-messenger-platform-20150128</string> <string>fb-messenger-platform-20150218</string> <string>fb-messenger-platform-20150305</string> 

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

 <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个不同的scheme(调用canOpenURL之后返回NO)。

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

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

点击此链接查看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> 

1]在Developer.facebook中进行身份validation并生成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