So, I've been messing around with the Facebook iOS SDK for a bit and as of the latest version I can't get the fbDidLogin method to be called. The login process works fine, with Safari used on the simulator and the Facebook app being used when running it on a device. However, after logging in I get transferred back to my app (as I should be) but as the fbDidLogin method hasn't been called, nothing has changed. As far as my app is concerned I'm not logged in. The demo app that is bundled with the SDK works fine. So I'm obviously doing something wrong, but I have no idea how to check what. I triple-checked all the methods used in the demo app against my own and as far as I can see everything looks the same. Any thoughts or ideas on how to debug this? Or has anyone had similar problems?
Thanks!
Source: Tips4all, CCNA FINAL EXAM
I encountered the same issue just now. I solved it by adding the following code into my application delegate:
ReplyDelete- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[controller facebook] handleOpenURL:url];
}
where controller is my UIViewController instance and facebook is my Facebook instance.
You also need to register your app to handle your fb application's URL scheme (do that in you Info.plist).
One common mistake could be to not implement the following callback method in your main app delegate, but elsewhere. Implement this method in your class derived from UIApplicationDelegate. This is the entry point that iOS calls after the context switch to bring your application back to foreground.
ReplyDelete- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// obtain facebook instance ref
[ facebook handleOpenURL: url ];
}
If you have created FB application Id correctly and mapped the URL appropriately as defined in https://developers.facebook.com/docs/guides/mobile/#ios then it should work.
I solved the problem, If facebook is the object of your first viewcontroller that is being loaded by ur appdelegate, then you can use viewcontroller property of appdelegate to refer facebook object e.g
ReplyDelete- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
[ viewController.facebook handleOpenURL: url ];
}
My cause for this was that I did not have the Facebook init in the ApDelegate using the correct delegate. I had it pointing to self, when it should be using the view controller where the user actually performed the login.
ReplyDeleteFrom AppDelegate:
facebook = [[Facebook alloc] initWithAppId:@"111111111111111" andDelegate:homeViewController];
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
ReplyDeletereturn [ facebook handleOpenURL:url];
}
should write on AppDelegate.m so that it will accessible for whole app.
please like it if it works