I updated both Parse and Facebook iOS SDKs to the latest versions, and when I try to login using Facebook my app crashes, and from the debugger I can see that it is calling 3-4 methods in an endless loop.
My login code looks like this:
- (void)openSession
{
UIViewController *topViewController = self.window.rootViewController;
NSArray *permissions = [NSArray arrayWithObjects:#"user_likes", #"friends_likes", nil];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
if (!user) {
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
}
} else if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
if ([[topViewController presentedViewController] isKindOfClass:[PALoginViewController class]]) {
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
} else {
NSLog(#"User with facebook logged in!");
if ([[topViewController presentedViewController] isKindOfClass:[PALoginViewController class]]) {
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
}
}];
}
The error occurs when logInWithPermissions is called. It crashes into Xcode and Debugger is showing an awful lot of calls to FB login methods - thousands actually:
What could be wrong?
This issue was reported as a bug on Facebook: https://developers.facebook.com/bugs/188127071335876?browse=search_5176d24c698df3761093726
It has now been fixed, and I can confirm that logging in now works - even with Sandbox enabled.
Sandbox off, then it should works.
Related
I have downloaded Parse's app, Anypic, but cannot get it to run properly on my phone. I have completed all of the required steps and it says "build succeeded" when I run it.
However, all that shows up is a black screen and a Facebook "login" button. When the button is clicked, you can login to Facebook but then it just changes the button to say "log out" which is not exactly wha
I have attached a picture with all my warnings I get. Are the warnings the issue or is there something else I need to change in the code? Thanks!
You should change handleFacebookSession part to look like this:
- (void)handleFacebookSession {
if ([PFUser currentUser]) {
if (self.delegate && [self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:[PFUser currentUser]];
}
return;
}
NSArray *permissionsArray = #[ #"public_profile",
#"user_friends",
#"email"];
self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
// Login PFUser using Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
NSString *errorMessage = nil;
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
errorMessage = #"Uh oh. The user cancelled the Facebook login.";
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
errorMessage = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log In Error"
message:errorMessage
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Dismiss", nil];
[alert show];
} else {
if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
} else {
NSLog(#"User with facebook logged in!");
}
if (!error) {
[self.hud removeFromSuperview];
if (self.delegate) {
if ([self.delegate respondsToSelector:#selector(logInViewControllerDidLogUserIn:)]) {
[self.delegate performSelector:#selector(logInViewControllerDidLogUserIn:) withObject:user];
}
}
} else {
[self cancelLogIn:error];
}
}
}];}
Found here.
When linking my iOS with Facebook through Parse with the following code I get the following error:
+[PFDateFormatter sharedFormatter]: unrecognized selector sent to class 0x1001f31d0
Unsure of how to handle this, and this error executes when the following block is called:
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[_activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
NSString *errorMessage = nil;
if (!error) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
errorMessage = #"Uh oh. The user cancelled the Facebook login.";
} else {
NSLog(#"Uh oh. An error occurred: %#", error);
errorMessage = [error localizedDescription];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Log In Error"
message:errorMessage
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Dismiss", nil];
[alert show];
} else {
if (user.isNew) {
NSLog(#"User with facebook signed up and logged in!");
} else {
NSLog(#"User with facebook logged in!");
}
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
I fixed this by removing all the Parse and Facebook frameworks from my project, and then adding this to my podfile:
pod 'Facebook-iOS-SDK'
pod 'Parse'
pod 'ParseFacebookUtils'
and reinstalling my podfile. For whatever reason, something is missing from the Parse or Facebook frameworks downloaded from the website. The podfiles fixed the issue for me.
I want to display display the Facebook login page in my app when the user is not signed-in yet. I'm using Facebook SDK for posting a status message on the users Facebook wall when the user allows the app.
Heres the code:
if (FBSession.activeSession.isOpen) {
// post to wall
#try {
[self postStatusMethod];
[self dismissViewControllerAnimated:YES completion:nil];
}
#catch (NSException *exception) {
NSLog(#"Error on posting to fb: %#", exception);
}
#finally {
}
} else {
// try to open session with existing valid token
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"read_stream",
#"publish_actions",
nil];
FBSession *session = [[FBSession alloc] initWithPermissions:permissions];
[FBSession setActiveSession:session];
if([FBSession openActiveSessionWithAllowLoginUI:NO]) {
// post to wall
#try {
[self postStatusMethod];
[self dismissViewControllerAnimated:YES completion:nil];
}
#catch (NSException *exception) {
NSLog(#"Error on posting to fb: %#", exception);
}
#finally {
}
} else {
// you need to log the user
[self userLogin];
}
}
how do i create the userLogin function so that is will display this:
Then, go back to the same view controller. i am using Facebook sdk.
Finally, i build the code:
-(void) userLogin {
NSLog(#"Clicked!");
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];
// If the session state is not any of the two "open" states when the button is clicked
} else {
// Open a session showing the user the login UI
// You must ALWAYS ask for public_profile permissions when opening a session
[FBSession openActiveSessionWithReadPermissions:#[#"public_profile"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
}];
}
}
But it goes back to my main menu not on the same menu where i click it.
I am using login with facebook in my app and getting username and profile pic from facebook. I have tested and it is working fine at my end, but apple has rejected it two times. I dont find any error at my end .
This is error by apple team:-
" We still found that your app exhibited one or more bugs, when reviewed on iPad Air running iOS 7.1 and an iPhone 5s running iOS 7.1, on both Wi-Fi and cellular networks, which is not in compliance with the App Store Review Guidelines.
Specifically, when we tap login to Facebook we get message say it wants to connect and when we tap ok it does not advance and connect with Facebook. "
Here is my Code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.login=[[ViewController alloc]init];
_nav = [[UINavigationController alloc] initWithRootViewController:self.login];
self.window.rootViewController = _nav;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.
// Whenever a person opens the app, check for a cached session
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
NSLog(#"Found a cached session");
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info", #"email", #"user_likes"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
// Handler for session state changes
// This method will be called EACH time the session state changes,
// also for intermediate states and NOT just when the session open
[self sessionStateChanged:session state:state error:error];
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(#"error:%#",error);
}
else
{
// retrive user's details at here as shown below
NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
[storeData setObject:user.id forKey:#"user_id"];
[storeData setObject:user.name forKey:#"name"];
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
}];
// If there's no cached session, we will show a login button
} else {
//UIButton *loginButton = [self.login loginButton];
//[loginButton setTitle:#"Log in with Facebook" forState:UIControlStateNormal];
}
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
// This method will handle ALL the session state changes in the app
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(#"Session opened");
// Show the user the logged-in UI
[self userLoggedIn];
return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
// If the session is closed
NSLog(#"Session closed");
// Show the user the logged-out UI
[self userLoggedOut];
}
// Handle errors
if (error){
NSLog(#"Error");
NSString *alertText;
NSString *alertTitle;
// If the error requires people using an app to make an action outside of the app in order to recover
if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
alertTitle = #"Something went wrong";
alertText = [FBErrorUtility userMessageForError:error];
[self showMessage:alertText withTitle:alertTitle];
} else {
// If the user cancelled login, do nothing
if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
NSLog(#"User cancelled login");
// Handle session closures that happen outside of the app
} else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
alertTitle = #"Session Error";
alertText = #"Your current session is no longer valid. Please log in again.";
[self showMessage:alertText withTitle:alertTitle];
// For simplicity, here we just show a generic message for all other errors
// You can learn how to handle other errors using our guide: https://developers.facebook.com/docs/ios/errors
} else {
//Get more error information from the error
NSDictionary *errorInformation = [[[error.userInfo objectForKey:#"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:#"body"] objectForKey:#"error"];
// Show the user an error message
alertTitle = #"Something went wrong";
alertText = [NSString stringWithFormat:#"Please retry. \n\n If the problem persists contact us and mention this error code: %#", [errorInformation objectForKey:#"message"]];
[self showMessage:alertText withTitle:alertTitle];
}
}
// Clear this token
[FBSession.activeSession closeAndClearTokenInformation];
// Show the user the logged-out UI
[self userLoggedOut];
}
}
// Show the user the logged-out UI
- (void)userLoggedOut
{
// Set the button title as "Log in with Facebook"
// UIButton *loginButton = [self.login loginButton];
//[loginButton setTitle:#"Log in with Facebook" forState:UIControlStateNormal];
// Confirm logout message
//[self showMessage:#"You're now logged out" withTitle:#""];
}
// Show the user the logged-in UI
- (void)userLoggedIn
{
// Set the button title as "Log out"
// UIButton *loginButton = self.login.loginButton;
//[loginButton setTitle:#"Log out" forState:UIControlStateNormal];
FrontViewController *v=[[FrontViewController alloc]init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:v];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
[self.nav pushViewController:revealController animated:YES];
[self showMessage:#"You're now logged in" withTitle:#"Welcome!"];
}
// Show an alert message
- (void)showMessage:(NSString *)text withTitle:(NSString *)title
{
[[[UIAlertView alloc] initWithTitle:title
message:text
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
}
// During the Facebook login flow, your app passes control to the Facebook iOS app or Facebook in a mobile browser.
// After authentication, your app will be called back with the session information.
// Override application:openURL:sourceApplication:annotation to call the FBsession object that handles the incoming URL
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Handle the user leaving the app while the Facebook login dialog is being shown
// For example: when the user presses the iOS "home" button while the login dialog is active
[FBAppCall handleDidBecomeActive];
}
In My View Controller
- (IBAction)buttonTouched:(id)sender
{
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];
// If the session state is not any of the two "open" states when the button is clicked
} else {
// Open a session showing the user the login UI
// You must ALWAYS ask for basic_info permissions when opening a session
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info", #"email", #"user_likes"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
// Retrieve the app delegate
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
[appDelegate sessionStateChanged:session state:state error:error];
switch (state) {
case FBSessionStateOpen:
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (error) {
NSLog(#"error:%#",error);
}
else
{
// retrive user's details at here as shown below
NSLog(#"FB user first name:%#",user.first_name);
NSUserDefaults *storeData=[NSUserDefaults standardUserDefaults];
[storeData setObject:user.id forKey:#"user_id"];
[storeData setObject:user.name forKey:#"name"];
}
}];
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
}];
}
}
Is your app on developer.facebook.com public and available for all users?
Status should look like this:
In other case if your app has status Developer Mode then other users can't authorise by Facebook.
I have exactly the same issue. Although it's a Flutter app, but the use-case is the same.
On my end, everything works as expected
Fb app has iOS and Bundle ID set correctly
FB app is public
But the Apple review team still rejects it. I asked for more Screenshots, which they provided, AND the screenshots clearly show the "continue" dialog of the FB-popup. So I don't understand why they rejected it.
My application supports login with facebook, but when I log out and log in again I am not asked for any credentials - it immediately logs in with the username which goes native in iOS6. I want something like in native facebook application:
When clicking "not you" facebook offers new login screen.
I followed this tutorial
The problem seems to be somewhere here:
- (void)openSession
{
NSArray *permissions=[NSArray arrayWithObjects: #"publish_stream", #"publish_actions",#"create_event", nil];
// [FBSession open]
[FBSession openActiveSessionWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceEveryone
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen: {
NSLog(#"Sesstion opened");
UIViewController *topViewController =
[self.navController topViewController];
NSLog(#"Class: %#", [[topViewController presentedViewController] class]);
if ([[topViewController presentedViewController]
isKindOfClass:[LoginViewController class]])
{
[topViewController dismissViewControllerAnimated:YES completion:nil];
}
ViewController *basic=(ViewController*)topViewController;
NSLog(#"Populating details");
[basic populateUserDetails];
}
break;
case FBSessionStateClosed:
{
NSLog(#"Session closed");
[FBSession.activeSession closeAndClearTokenInformation];
}
case FBSessionStateClosedLoginFailed:
NSLog(#"Login failed");
[self.navController popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
[self showLoginView];
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
I am not sure the Facebook SDK supports that - although I might be wrong. The idea (as I understand it) is that Facebook login allows the currently logged in Facebook user to login to your app. If no one is logged in to Facebook, the credentials page will be shown. After providing valid credentials, the user will be logged in to Facebook and an auth_token is sent to your app.
The point is that you can't authenticate a different user than the one currently logged in to Facebook. That would first require a logout of the current user and I think Facebook wish to keep this "change user" functionality to the Facebook app.
Also, note that when logging out from your app, the user stays logged in to Facebook. This is different from the policy that applies to web sites that use Facebook authentication. In that case, the user should be logged out both from the site and from Facebook.