39

I am trying to Log In a user via Facebook. In the previous version of swift 1.2 everything worked perfectly, but after migration I can't seem to log in via my FB account I am still getting the error saying:

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

Can you please help me with that?

kalafun
  • 3,512
  • 6
  • 35
  • 49

4 Answers4

34

From the WWDC 2015 "Privacy and Your App" video, add the following to your info.plist file:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth</string>
    </array>
Mark A. Durham
  • 844
  • 1
  • 6
  • 18
  • Try the following as it works for me. Create a new Swift 2.0 app for iOS 9 in Xcode 7. In the AppDelegate.swift file, add `let sharedApplication = UIApplication.sharedApplication(); let isFacebookAuthorized = sharedApplication.canOpenURL(NSURL(fileURLWithPath: "fbauth://authorize"));` into didFinishLaunchingWithOptions. Build and run. You should get the "not allowed to query for scheme" error. Next, open Info.plist as source code and insert the code from my original reply into the file just in front of ``. Rebuild and run. You should no longer get the error. – Mark A. Durham Jun 16 '15 at 13:57
  • I have came back to Xcode 6 in the meantime, will wait for Parse and FBSDK to actually release a new version that will work on iOS9 and also has built libraries with bitcode – kalafun Jun 17 '15 at 08:22
  • A working code example can be found here: https://github.com/gatzsche/LSApplicationQueriesSchemes-Working-Example – Awsed Jun 29 '15 at 11:42
  • 10
    Got the same issue, after add this to the Info.plist I got this: -canOpenURL: failed for URL: "fbauth://authorize/?client_id=…" - error: "(null)", seems like the FBSDK has something wrong. – nebiros Jul 06 '15 at 22:02
  • @nebiros To my knowledge error: "(null)" this error is only shown if the requested app is in the whitelist but not installed on the system. – Awsed Jul 08 '15 at 07:05
  • @VanDuTran could you please share how you fixed it? – Eduardo Jul 08 '15 at 22:38
  • @Eduardo I did exactly like this answer pointed out. I added the LSApplicationQueriesSchemes key with fbauth. – Van Du Tran Jul 10 '15 at 14:44
  • @nebiros I am facing the same issue. The only difference I found is that in - error: "This app is not allowed to query for scheme fbauth", after adding above lines in my plist file I am getting error: - "(null)" but previous is same.. -canOpenURL: failed for URL: "fbauth://authorize/?client_id=........ – Dimple Shah Sep 28 '15 at 07:21
  • If you have added the LSApplicationQueriesSchemes to your info.plist, you can ignore those error messages(such as 'This app is not allowed to query for scheme.....'). It is just a bug of Xcode 7, which doesn't affect you integration with Facebook – JSNoob Oct 20 '15 at 17:20
28

I suggest following the instructions from Facebook to prepare an app for iOS 9: https://developers.facebook.com/docs/ios/ios9

  1. Download the latest Facebook SDK for iOS

Download the appropriate version of the Facebook SDK for your app.

v4.x - Recommended. v3.24.0 - Only if you have not migrated to v4.x of the SDK yet. 2. Whitelist Facebook Servers for Network Requests

If you compile your app with iOS SDK 9.0, you will be affected by App Transport Security. Currently, you will need to whitelist Facebook domains in your app by adding the following to your application's plist:

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

or you will encounter errors like:

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. Whitelist Facebook Apps

If you use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, you will need to update your application's plist to handle the changes to canOpenURL described in https://developer.apple.com/videos/wwdc/2015/?id=703

If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the SDK v4.5 or older:

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

If you're using FBSDKMessengerShareKit from versions older than the v4.6 release, also add

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

If you're using v4.6.0 of the SDK, you only need to add:

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

This will allow the FacebookSDK integration to properly identify installed Facebook apps to perform an app switch. If you are not recompiling with iOS SDK 9.0, your app is limited to 50 distinct schemes (calls to canOpenURL afterwards return NO).

mogile_oli
  • 2,148
  • 2
  • 21
  • 21
  • I was curious about the `akamaihd.net` portion of this response, as it didn't seem connected with facebook, and googled it and found a whole bunch of info related to malware and related issues. It appears that its a CDN that facebook uses, but are we sure this is required? – Mike Sep 22 '15 at 17:08
  • this answer is really amazing, it's cover almost all of it. – Sruit A.Suk Oct 02 '15 at 22:21
5

Follow this link to see Facebook's reccommended updates for iOS 9 https://developers.facebook.com/docs/ios/ios9

In order to fix this specific error

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

For Facebook SDK version 4.6+ go to your info.plist file and add the following:

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

For version 4.5 or older:

<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>
Khaled Zayed
  • 306
  • 2
  • 6
  • I'm running <4.5, and had to add `fb-messenger-platform-20150128`. In other words, to add the exact scheme from my error message, which was `"This app is not allowed to query for scheme fb-messenger-platform-20150218"` – Stan James Oct 24 '15 at 14:56
0

1] Authentication in Developer.facebook and generate Facebook Id

2] Set Bitcode : No From Build Settings

3] Set up Plist File

<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] Download 4 Sdk Framework like

=>Bolts.framework
=>FBSDKCoreKit.framework
=>FBSDKLoginKit.framework
=>FBSDKShareKit.framework
Nikunj Patel
  • 304
  • 2
  • 7