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

I work through the Facebook API for my iPhone application and have two questions:

All documents / examples seem to put everything in appDelegate: creating a Facebook object and authorizing in appDidFinishLaunching and overriding the application: handleOpenURL method.

In my application, I do not want something to happen if the user does not switch to a specific view and presses a button. I understand that from this point of view I will create an instance of the Facebook object and begin authorization in the button handler method, but what about handling the application override: handleOpenURL? I would have to use a different FB object (an instance in my application delta) than the one used in my particular view controller.

  • Does this situation mean a singleton? Or is it a good design solution that allows my appDelegate to instantiate an FB object and access it wherever I need it in my program?

    In the FB docs, they tell you to override the application: the handleOpenURL method:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [facebook handleOpenURL:url]; } 
  • As written, doesn't that mean that your application can only open one type of URL? If you need an application to answer no more than one, you need to analyze the url parameter to find out what action you need to take, fix it?

Thanks!

+8
ios facebook facebook-graph-api facebook-ios-sdk
source share
1 answer

1) Both solutions - approx. But, of course, it’s cleaner to use singleton, especially if you intend to reuse it in your application.

2) application:handleOpenURL method: - the way to call the application from outside FB sdk allows you to authenticate your facebook application, if installed, or safari. After authentication, your application is called using this handler. It works specifically with devices that support multitasking. This is the preferred way to simplify login and session sharing. But this is not necessary ... An application can support several URL schemes declared in the application that you can check (unchecked, but there should be something like this):

 - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { if ([url.scheme isEqualToString:@"fb<yourid>"]) return [facebook handleOpenURL:url]; else { // do what you want return YES; } } 
+9
source share

All Articles