I\'m trying to implement Facebook login in my iOS app, using Parse.
let permissionsArray = [\"public_profile\", \"email\"]
PFFacebookUtils.logInInBackgroun
I got the same problem when I was trying to catch login and logout event as below
loginButton = [[FBSDKLoginButton alloc] init];
// Handle clicks on the button
[loginButton
addTarget:self
action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];
// Once the button is clicked, show the login dialog
-(void)loginButtonClicked
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
}
}];
}
But this is only good for a custom login button, if you are using default fb login button, the FBSDKLoginManager has been initialized already, you will get the error when trying to create another one.
So, in order to catch login and logout event, just set the delegate for login button and then handle it like the following:
loginButton = [[FBSDKLoginButton alloc] init];
loginButton.delegate = self;
- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
if (!error) {
[self getFBProfile];
}
}
- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {
[self logout];
}