FBSDKLoginManager does not handle logInWithPublishPermissions: correct

I am using v4.1 for the iOS SDK and when I try to call publishPermissions I don't get a callback.

For some reason, everything works fine when I run logInWithReadPermissions :, but when I run logInWithPublishPermissions: it never gets to my response handler. Nothing happened.

To test the situation, I reset my loginManager before running logInWithPublishPermissions :, and to my surprise it worked then (eg NSLog (@ "RESULT") is called).

Am I missing something about how loginManager works? Should I use it without restarting it?

// FacebookController.m

@implementation FacebookController

FBSDKLoginManager *loginManager;
static FacebookController *_shared = nil;

- (id)init { 
    self = [super init];
    if (self != nil) {
        userData = [[NSMutableDictionary alloc] init];

        loginManager = [[FBSDKLoginManager alloc] init];
    }
    return self;
}

+ (id)getInstance { 
    if (!_shared) {
        _shared = [[self alloc] init];
    }
    return _shared;
}

- (bool)hasPublishPermissions {
    FBSDKAccessToken *accessToken = [FBSDKAccessToken currentAccessToken];

    if(accessToken != NULL){
        NSSet *permissions = [accessToken permissions];
        if([permissions containsObject:@"publish_actions"]){
            return TRUE;
        }
    }
    return FALSE;
}

- (void)requestPublishPermissionsWithDelegate:(id)aDelegate {
    if(![self hasPublishPermissions]){
        // FOR SOME REASON IT WORKS IF I RESET LOGIN MANAGER AS FOLLOWS
        // loginManager = [[FBSDKLoginManager alloc] init]; 

        [loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
            NSLog(@"RESULT: %@", result);
        }];
    }
}

- (void)connectToFacebookWithDelegate:(id)aDelegate {        
    FBSDKAccessToken *accessToken = [FBSDKAccessToken currentAccessToken];

    if(accessToken != nil){
        [aDelegate performSelector:@selector(facebookSignedIn)];
    } else {
        [loginManager logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
            if (error) {
                // Process error
                NSLog(@"ERROR");
            } else if (result.isCancelled) {
                // Handle cancellations
                NSLog(@"CANCELLED");
            } else {
                NSLog(@"SUCCESS");
                [aDelegate performSelector:@selector(facebookSignedIn)];
            }
        }];
    }
}
@end

      

Edit # 1: Including videos of how they work and don't work for these scenarios:

Doesn't work (reinitializing loginManager): https://dl.dropboxusercontent.com/u/14277258/not-working.mov

Working (loginManager reinitialized): https://dl.dropboxusercontent.com/u/14277258/working.mov

+3


source to share


1 answer


Your video stack trace indicates that you are invoking a post permission request inside the handler for your initial login. This should be avoided:

  • You call another login after the user has already granted you some permissions - not good for the user to see another login dialog right after it completes.
  • You are asking for permission to post when you don’t need it - this could violate Facebook's developer policies and again not the best user experience. Instead, you should only request a post when you need it (i.e. during sharing).


If you really insist, you can send your second login asynchronously so that the first request completes completely, but I would not recommend it. We can probably update the SDK to detect this and record, although it's not that confusing.

+1


source







All Articles