Aviram Netanel Aviram Netanel - 2 months ago 15
Objective-C Question

ios Facebook Login button - doesn't change to Log out

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?

Answer

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!

Comments