Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook API - where to instantiate and how to properly implement handleOpenURL

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.

  1. 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]; 
}
  1. As written, doesn't this mean your application will only be able to open one type of url? If you're app needed to respond to more than just one, you'd need to parse the url parameter to figure out which action to take, correct?

Thanks!

like image 969
djibouti33 Avatar asked Feb 22 '11 06:02

djibouti33


1 Answers

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;
  }
}
like image 109
Vincent Guerci Avatar answered Nov 10 '22 20:11

Vincent Guerci