I'm working through the Facebook API for my iPhone app, and have two questions:
All documentation/examples seem to put everything in the appDelegate: instantiating the Facebook object and authorizing in appDidFinishLaunching, and overriding the application:handleOpenURL method.
In my app, I don't want anything to happen unless a user navigates to a specific view and presses a button. I understand that in that view, I'll instantiate the Facebook object and start the authorization in the button handler method, but what about handling the overriding of application:handleOpenURL? I'd have to use a different FB object (instantiated in my app delegate) than the one used in my particular view controller.
Does this situation call for a singleton? Or is it a good design solution to let my appDelegate instantiate the FB object, and access it through there wherever else I need it in my program?
In the FB docs, they tell you to override the application:handleOpenURL method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
Thanks!
1) Both solutions are Ok. But It is of course cleaner to use a singleton, especially if you intend to re-use it across your application.
2) application:handleOpenURL method:
is the way to call an application externally
FB sdk allows authent from facebook app if installed or safari. Once authenticated your app is called back using this handler.
It works that way only with devices supporting multitasking
It is the preferred way to ease login and share session. But it is not mandatory...
An app can support several URL schemes declared in application that you can check (untested but should be something like that):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([url.scheme isEqualToString:@"fb<yourid>"])
return [facebook handleOpenURL:url];
else {
// do what you want
return YES;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With