Native Facebook Login stopped working after SDK update to 3.14
I just ran to this issue also, here's the details on what has happened & how I fixed my app.
Bottom line
Due to the new login process wherein users can now approve / deny each requested permission (something not supported by the native ios integrated login), Facebook has changed the sdk's default login behavior to first try the Facebook fast app switch & then fall back on the web view, completely ignoring any ios system level Facebook credentials.
This is noted in the upgrade guide (form 3.13 > 3.14) here: https://developers.facebook.com/docs/ios/upgrading
Relevant portion:
"The default login behavior has changed from FBSessionLoginBehaviorUseSystemAccountIfPresent to FBSessionLoginBehaviorWithFallbackToWebView."
So what to do?
Well, if you don't need any of the new things, FBLikeControl etc..., that were introduced in 3.14, you could just downgrade to 3.13. However, if you want/need to use 3.14n there's an instance method on FBSession that takes the FBSessionLoginBehavior as a parameter: https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#openWithBehavior:completionHandler:
I updated the body of my method for opening a Facebook session from:
[FBSession openActiveSessionWithReadPermissions:@[@"email", @"user_location"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}
];
to:
FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session state:status error:error];
};
if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) {
// we have a cached token, so open the session
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completionHandler];
} else {
[self clearAllUserInfo];
// create a new facebook session
FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"email", @"user_location"]];
[FBSession setActiveSession:fbSession];
[fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
completionHandler:completionHandler];
}
NOTE: my clearAllUserInfo method includes the following lines:
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
NSLog(@"%@", error);
}];
[FBSession setActiveSession:nil];
It's also worth checking out the Facebook documentation on understanding sessions: http://developers.facebook.com/docs/facebook-login/ios/v2.0#sessions
Can't get native login to work with Facebook iOS SDK
To get authenticated from the native facebook app, you need to FacebookAppID and url type in info.plist file, make sure you're using same bundle identifier as you mentioned in facebook app settings.
Check screenshot:
I am new to Facebook SDK with iOS. I want to send invitation to friends on Facebook
Login doesn't work/stuck with Latest Facebook SDK
I was having the same problem. Add this to your AppDelegate:
In AppDelegate.m
In
application:didFinishLaunchingWithOptions:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}Add the following method to your AppDelegate.m:
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
I don't know if the SafariViewController
checks for the application:openURL:sourceApplication:annotation
but this worked for me.
Give it a try. I hope it works for you.
Source: https://developers.facebook.com/docs/ios/getting-started
Facebook iOS SDK native login not working
The answer to
'why native login is not working with latest FB SDK is still a
mystery'?
is here. See the upgrade guide form 3.13 > 3.14.
The default login behavior has changed from FBSessionLoginBehaviorUseSystemAccountIfPresent
to FBSessionLoginBehaviorWithFallbackToWebView
Facebook login fails (always isCancelled) after upgrading to SDK 4.1
Thanks to Dheeraj and its answer to a similar question, I found the error in my calls. I just made the stupidest error in Swift. In the unlikely event someone as dumb as I am read this, here are the 3 calls in Swift that you should add in your AppDelegate.swift. They are tested and working:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Do what you have to do but at the end, instead of 'return true', put :
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
Related Topics
How to Get iOS Appstorereceipturl into Base 64 Encoded String
What Does Warning "Mapping Architecture Arm64 to X86_64" Mean
How to Set-Up in App Purchase Free Trial Period in iOS App
How to Get Image File Size in Swift
Understanding Uilocalnotification Timezone
Any Way to Install App to iPhone 4 with Xcode 8 Beta
Using Arc, Is It Fatal Not to Have an Autorelease Pool for Every Thread
Prevent Duplicate Symbols When Building Static Library with Cocoapods
Detect If a Point Is Inside a Mkpolygon Overlay
How to Use Sf Symbols in iOS 12 and Below
Objective-C Delay Action with Blocks
Why the Extension Is "Momd" But Not "Xcdatamodel" When Search the Path for the Model File
How to Link Googleanalytics 3.01 with Xcode 5 (Missing Required Architecture X86_64)
How to Change the Highlighted Color of a Uibutton
Transparent Uinavigationbar in Swift
How to Return Value After the Execution of the Block? Swift
iOS How to Asynchronously Download and Cache Images and Videos for Use in My App