This is very weird. I'm trying to login to Facebook and everything is working fine if there's no Facebook app is installed on the device. But if there's this app then nothing happens. Just nothing. Completion block is never called and no login dialog appears. This is my very simple code:
[PFFacebookUtils logInInBackgroundWithReadPermissions:@[@"public_profile"] block:^(PFUser *user, NSError *error)
{
NSLog(@"Completion");
}];
I also have this code inside applicationDidFinishLauncing
:
[Parse setApplicationId:kPAParseApplicationId clientKey:kPAParseClientKey];
[PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];
and I have the following method implemented:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
I also need to note the following: sometimes, very rarely, it works even with the app installed. Works and then again stops working without any reason. Did anyone encounter such a problem? Thanks!
I've figured it out. The problem was in the Facebook SDK itself and I've managed to fix it. It has nothing to do with
Facebook
app being installed or not.Luckily,
FBSDKLoginKit
andFBSDKCoreKit
are open source so I was able to track down the problem. So,FBSDKLoginManager
allows login only if it has an active SDK configuration loaded fromFacebook
server. If it doesn't then it simply do nothing without even logging some error message to help the developer. So what is the reason it doesn't have active configuration sometimes. The reason is thatFBSDKURLConnection
doesn't schedule itsNSURLConnection
on the main run loop. So if itsstart
method is called on background thread thenNSURLConnection
delegate methods may be called or they may be not called. And if they are not then there's no new configuration loaded and you are unable to login. So what I did was simply modifyFBSDKURLConnection
'sstart
method like this:and now it works