PFFacebookUtils logInInBackgroundWithReadPermissions: block: opens Facebook app instead of using system account

867 views Asked by At

I've upgraded to ParseFacebookUtilsV4 and I've updated my login code as such:

[PFFacebookUtils logInInBackgroundWithReadPermissions:FACEBOOK_READ_PERMISSIONS block:^(PFUser *user, NSError *error) {
  ...
}];

However, now my app switches to Facebook app for a brief moment and comes back. It uses the native Facebook app to login, while there is still a valid iOS Facebook account in Settings. How can I make PFFacebookUtils v4 use the system Facebook account when available, and only fall back to Facebook app when a system account is not available?

3

There are 3 answers

0
Vitalii Gozhenko On

Fork Parse library from Github

Go inside it, and change whatever you want...

0
Larry Pickles On

From the Header files of ParseFacebookUtilsV4

PFFacebookUtils.h

...

/*! @abstract FBSDKLoginManager provides methods for configuring login behavior, default audience and managing Facebook Access Token.

@returns An instance of FBSDKLoginManager that is used by PFFacebookUtils. */

+ (FBSDKLoginManager *)facebookLoginManager;

Therefore, supposedly, a declaration of "FBSDKLoginManager" is used by PFFacebookutils, let's see if this works. In fact, let's set the default to "system account", ... here's the code:

[[PFFacebookUtils facebookLoginManager] setLoginBehavior:FBSDKLoginBehaviorSystemAccount];

[PFFacebookUtils logInInBackgroundWithReadPermissions:FACEBOOK_READ_PERMISSIONS block:^(PFUser *user, NSError *error) {
}]; 

Yes, this code compiles, this code works, just make sure you declare the login behavior before you call the login stuff, and preferably in your AppDelegate when you are initializing your code bases, Parse, Parse Facebook Utilities, etc. ..

In fact, to make sure this works for you, I just downloaded the MOST up to date version of PARSE iOS SDK and it has this same functionality. Here are your options, this is from the Facebook SDK for iOS which feeds the PFFacebookUtils:

@typedef FBSDKLoginBehavior enum

@abstract Passed to the \c FBSDKLoginManager to indicate how Facebook Login should be attempted.

@discussion Facebook Login authorizes the application to act on behalf of the user, using the user's Facebook account. Usually a Facebook Login will rely on an account maintained outside of the application, by the native Facebook application, the browser, or perhaps the device itself. This avoids the need for a user to enter their username and password directly, and provides the most secure and lowest friction way for a user to authorize the application to interact with Facebook.

The \c FBSDKLoginBehavior enum specifies which log in method should be attempted. Most applications will use the default, which attempts a login through the Facebook app and falls back to the browser if needed.

If log in cannot be completed using the specificed behavior, the completion handler will be invoked with an error in the \c FBSDKErrorDomain and a code of \c FBSDKLoginUnknownErrorCode. */

typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
  /*!
   @abstract Attempts log in through the native Facebook app. If the Facebook app is
   not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the
   default behavior.
   */
  FBSDKLoginBehaviorNative = 0,
  /*!
   @abstract Attempts log in through the Safari browser
   */
  FBSDKLoginBehaviorBrowser,
  /*!
   @abstract Attempts log in through the Facebook account currently signed in through Settings.
   If no Facebook account is signed in, falls back to \c FBSDKLoginBehaviorNative.
   */
  FBSDKLoginBehaviorSystemAccount,
  /*!
   @abstract Attemps log in through a modal \c UIWebView pop up

   @note This behavior is only available to certain types of apps. Please check the Facebook
   Platform Policy to verify your app meets the restrictions.
   */
  FBSDKLoginBehaviorWeb,
};
4
der_michael On

Opening the Facebook app is the preferred scenario for authenticating with your app according to the SDK. This behavior is defined by Facebook and their SDK and not a Parse issue really.

Unless you want to add a whole bunch of custom code to interface with iOS system account directly you'd have to live with the app opening and returning to your app. Thats how everyone does it... (I know, kind of lame answer)

If you want to try yourself, start looking into

ACAccountType *facebookAccountType = [[[ACAccountStore alloc] init] accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];