Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK 4.6 login button on iOS doesn't use Facebook app for authentication

Tags:

ios

facebook

I'm using the Facebook SDK v4.6.0 for iOS 9 in a simple Swift app to add a login button to my app (I've followed the steps in Preparing Your Apps for iOS 9).

The login button always opens Safari to authenticate, and never uses the native Facebook app. Is this the expected behavior? Is it possible to use the native app (where many users are already authenticated) instead of going straight to the web login?

I've tried testing the app on my iPhone by building and running using XCode, and with a build distributed by TestFlight. It always opens Safari to authenticate, even though I have the native app installed and configured.

I found this relevant question where the answer seems to apply only to the 3.x SDK. I've also found other questions that had references to configuring tryFBAppAuth or authorizeWithFBAppAuth that seemed to apply to edge cases on previous versions of the FB SDK. I haven't found a clear answer for 4.6.

like image 680
Matt Hampel Avatar asked Sep 01 '15 17:09

Matt Hampel


People also ask

How initialize Facebook SDK iOS?

In Xcode, click File > Swift Packages > Add Package Dependency. In the dialog that appears, enter the repository URL: https://github.com/facebook/facebook-ios-sdk. In Version, select Up to Next Major and the default option. Complete the prompts to select the libraries you want to use in your project.

What is Facebook SDK for iOS?

The Facebook SDK is what allows mobile app developers to integrate Facebook within a mobile app. SDK stands for software development kit, and it allows for a website or app to integrate with Facebook seamlessly.


2 Answers

This is by design. I have filled a bug report a few days ago and Facebook still has some issue with iOS 9.

See the Facebook team answer: https://developers.facebook.com/bugs/786729821439894/?search_id

like image 103
Bastien Avatar answered Sep 28 '22 14:09

Bastien


You need to whitelist the facebook native app. In your info.plist, make sure you have the following entry

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

Unless you whitelist an url scheme, your iOS app won't be able to switch to that app. The facebook SDK will display Safari instead of the native app in that case.

like image 20
Med Hajlaoui Avatar answered Sep 28 '22 15:09

Med Hajlaoui