Question

Trying to make a design decision on how to implement callbacks from the Facebook SDK for iOS. Right now I have created a helper (singleton) class called FacebookHelper to hold the Facebook instance and implement the delegate methods like - (void)request:(FBRequest *)request didLoad:(id)result, - (void)fbDidLogout and so on.

With this option I then post notifications when the delegate methods are called, and the interested UIViewControllers can subscribe to the notifications and then handle the updates.

Another option I thought of is to have the AppDelegate be the delegate of the Facebook instance and then implement all the delegate methods and from the delegate methods inform the visible UIViewController (if it's interested) that some Facebook update has occurred.

Basically I have only two receivers that are interested in Facebook updates; one is the AppDelegate and the other is ViewControllerX.

Was it helpful?

Solution

Peter, I think the notification method may work out better. Here's why:

When using the delegate approach you can't have multiple view controllers assigning themselves as the facebook singleton delegate. Therefore, you have to have one delegate (the App Delegate as you suggested) which then acts as an intermediate object to then notify the other objects that something happened. This seems unnecessarily convoluted...

Using the notification method, you can just have your facebook object post notifications about events and anyone who is interested can listen. This skips the middle man and leaves your code easily expandable should you ever want more than one viewControllerX that is interested in what facebook is doing.

I mean, it's all a matter of style but for what it's worth (maybe not much haha) that's my opinion.

OTHER TIPS

The App Delegate should handle UIApplication delegate methods only. (Well, IMHO, but I think you'll find that's a fairly popular opinion.)

If you need a Facebook Delegate then that sounds like an eminently sensible thing to have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top