3

I'm using Xcode 6 & Facebook iOS SDK 4.3, I embedded the code, according to Facebook's guide and the login works, BUT from some reason -

after I login, the button doesn't change to "Log out", and stays "Log in with Facebook".

did anyone encounter this problem?

Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69

3 Answers3

6

so I started all over, and followed the instructions from the guide:

1.in the viewController.h file:

#import < FBSDKCoreKit/FBSDKCoreKit.h> //<-delete the space

#import < FBSDKLoginKit/FBSDKLoginKit.h>//<-delete the space

@interface ViewController : UIViewController<FBSDKLoginButtonDelegate>
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;

2.in the viewController.m file:

-(void) viewDidLoad{
   if ([FBSDKAccessToken currentAccessToken]) {
   // User is logged in, do work such as go to next view controller. 
   }

   self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];

   FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
  [self.view addSubview:loginButton];
}

and after that didn't work, I've found this thread that mentioned I also need to add few things to the AppDelegate didFinishLaunchingWithOptions :

return [[FBSDKApplicationDelegate sharedInstance] application:application
                                didFinishLaunchingWithOptions:launchOptions];

and

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url
                                            sourceApplication:sourceApplication
                                                   annotation:annotation];
}

and then it worked! finally I had the Log in button changed to Log out!

Community
  • 1
  • 1
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69
  • 1
    Thanks for that! I've been struggling with FB's docs. They are very obscure in my opinion. Anyway you solved my problem :) – devdc Aug 21 '15 at 08:46
  • 1
    Adding- it turns that its not just that the login changes to logout, but the login process won't finish with out `application:openUrl:sourceApplication:annotation`. So now I can use the login result object. – devdc Aug 21 '15 at 08:52
  • 1
    As said by @Gab, in simulators u may not see logout button change automatically. – Irshad Mohamed Oct 22 '16 at 06:30
2

I was experiencing the same issue, and couldn't find the answer anywhere. Turns out it was a Simulator problem; once I ran the same code on the device (iOS 9.3.1) everything worked out fine.

0

Remember to enable keychain sharing capability

Andres Diez
  • 21
  • 1
  • 2