Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 9 Swift - Parse Facebook login does not open native Facebook App

I've integrated Parse Framework with all Facebook dependencies to my App. My plist configuration looks like this:

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fbXXXXXXXXXXXXX</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>XXXXXXXXXXXXX</string>
    <key>FacebookDisplayName</key>
    <string>XXXXX</string>

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

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>fbauth2</string>
    </array>

My Login code looks like so:

PFFacebookUtils.logInInBackgroundWithReadPermissions(permissionsArray, block: { (user, error) -> Void in
            if(error != nil){
                print("Login failed")
            }else{
                if let currentUser = user{
                    if(currentUser.isNew){
                        print("New user")
                    }else{
                        print("Login success")
                    }
                }else{
                    print("Login canceled")
                }

            }
        })

All works well, however the login process is being done in Safari and not in the installed Facebook App.

What am I missing?

like image 938
Shlomi Schwartz Avatar asked Nov 22 '15 13:11

Shlomi Schwartz


People also ask

How do I login to my Facebook account on iOS?

Build and run your iOS app, you should see a blue color Facebook login button at the center of the screen. Click on the login button, you will be presented the Facebook login page. Enter the test user’s email address and password to proceed with login. If you setup everything correctly, you should see a confirmation page.

What happens when people log into my app with Facebook?

When people log into your app with Facebook, they can grant permissions to your app so you can retrieve information or perform actions on Facebook on their behalf. The following steps are for adding Facebook Login to your iOS project.

How to setup Facebook single sign on with Xcode?

Go ahead and copy the bundle identifier from your Xcode project’s application target and paste it into the “Bundle ID” field. After that turn on “Single Sign On” and then click “Save Changes”. With that, you have completed the setup required on your Facebook app.

How do I integrate the SDK with a native Facebook app?

Replace the code in AppDelegate.swift method with the following code. This code initializes the SDK when your app launches, and allows the SDK handle results from the native Facebook app when you perform a Login or Share action.


1 Answers

Since iOS 9 Facebook SDK no longer offers authorisation via Facebook App. The reason is that users will be prompted before app can open other app and this affects UX.

Your only option is to use FBSDKLoginBehaviorSystemAccount or FBSDKLoginBehaviorBrowser

PFFacebookUtils.facebookLoginManager().loginBehavior = FBSDKLoginBehavior.SystemAccount
like image 165
Armands L. Avatar answered Sep 18 '22 21:09

Armands L.