我正在尝试通过Facebook登录用户。在之前的Swift 1.2版本中,一切都运行得很完美,但迁移后,我似乎无法通过我的FB帐户登录,仍然会收到以下错误:
- canOpenURL:针对URL失败:"fbauth://authorize/?client_id=... 错误:"此应用程序不允许查询方案fbauth"
请问你能帮我解决这个问题吗?
我正在尝试通过Facebook登录用户。在之前的Swift 1.2版本中,一切都运行得很完美,但迁移后,我似乎无法通过我的FB帐户登录,仍然会收到以下错误:
- canOpenURL:针对URL失败:"fbauth://authorize/?client_id=... 错误:"此应用程序不允许查询方案fbauth"
请问你能帮我解决这个问题吗?
从 WWDC 2015 的 "隐私与您的应用程序" 视频中,将以下内容添加到您的 info.plist 文件中:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbauth</string>
</array>
let sharedApplication = UIApplication.sharedApplication(); let isFacebookAuthorized = sharedApplication.canOpenURL(NSURL(fileURLWithPath: "fbauth://authorize"));
放置在didFinishLaunchingWithOptions方法中。构建并运行应用程序。您应该会收到“不允许查询方案”的错误提示。接下来,以源代码模式打开Info.plist文件,并将代码插入到我的原始回复中,在</dict>
前面。重新构建和运行应用程序。您应该不再收到错误提示。 - Mark A. Durham建议按照Facebook的指示,为iOS 9准备应用程序:
https://developers.facebook.com/docs/ios/ios9下载适合您的应用程序的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应用程序,那么您需要更新应用程序的plist以处理canOpenURL的更改,有关详细信息,请参见https://developer.apple.com/videos/wwdc/2015/?id=703
如果您正在重新编译iOS SDK 9.0,则在应用程序的plist中添加以下内容,如果您使用的是SDK v4.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>
如果您正在使用早于v4.6版本的FBSDKMessengerShareKit,请同时添加以下内容:
<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
如果您正在使用4.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,但我们确定需要吗? - Mike-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>
。换句话说,要添加来自我的错误消息的确切方案,该消息是“此应用程序不允许查询方案fb-messenger-platform-20150218”。 - Stan James1] 在 Developer.facebook 上进行身份验证并生成 Facebook Id
2] 设置 Bitcode:从构建设置中选择“否”
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