13
votes

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.

3

3 Answers

7
votes

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

6
votes

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.

1
votes

Are you compiling with iOS9 SDK (XCode 7.x)? As mentioned in FB's iOS9 preparation page you should be compiling with the new SDK for app switching policies to take place.