问题
I have a Facebook login-enabled app and for some reason FBSDKLoginManager logInWithReadPermissions: fromViewController: handler: is not called on the very first run of my app after installation. If I just kill my app (even without trying to login to Facebook or do anything: trying to login on first open or not doesn't change anything) and open it again, it works perfectly.
Why?
(I've checked the view controller passed to the method is not nil and is the current view controller)
Here is my login code:
+(void)loginWithFacebookWithCompletion:(ULCompletion)completion{
[[[FBSDKLoginManager alloc] init] logInWithReadPermissions:FACEBOOK_READ_PERMISSIONS fromViewController:[ULMasterViewController instance] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if(result.token){
...
}
[...]
The rest is irrelevant as the completion block is not called at all (not even with an error). I've got the FACEBOOK_READ_PERMISSIONS hardcoded:
#define FACEBOOK_READ_PERMISSIONS (@[@"user_friends", @"user_birthday", @"email", @"user_photos"])
And finally, [ULMasterViewController instance] is valid (not nil, and has its view in hierarchy (otherwise it complains about view not being in hiearchy, also tried that)).
回答1:
This working in my case .
1 .Create instance of FBloginManager in interface.
FBSDKLoginManager *manager
2 .Initialise in ViewDidLoad.
manager = [FBSDKLoginManager new]
3 .And finally call login permission method using this instace of FBLoginManager.
回答2:
I ran into this exact problem and it was very frustrating. The key to fixing it turned was that my app code was making lots of concurrently existing FBSDKLoginManager objects. Refactoring my code to use a singleton shared instance (as opposed to running [FBSDKLoginManager new] all over the place) eliminated this bug/issue for me.
Mysteriously, I never understood why this worked. I used the debugger to trace into the FBSDK code, and the only (very) mysterious issue I found was that from inside the loginWithReadPermissions method, the fromViewController parameter was being set to nil even though I was passing in a non-nil value. Strange...
回答3:
This is not much relevant but try by creating FBSDKLoginManager object separately as i have done same and working for me.
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
来源:https://stackoverflow.com/questions/40089124/fbsdkloginmanager-loginwithreadpermissions-fromviewcontroller-handler-complet