On which ViewController should I implement FacebookSDK's removeObserver?

I am implementing facebook's SDK for iOS into my app. There are two functions however that are supposed to register and unregister for the notifications:

From Facebook's login to facebook with ios:

in the viewDidLoad method, register for the session change notification you defined in the app delegate by adding this code to the end of the method:

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sessionStateChanged:)
name:FBSessionStateChangedNotification
object:nil];

and

Unregister for the notifications by adding the following code to the end of the didReceiveMemoryWarning the method:

[[NSNotificationCenter defaultCenter] removeObserver:self];

Since I have quite a few view controllers and all of them should be using facebook's API, I thought I should implement the register/unregister methods in the applicationDidFinishLoadingWithOptions (for register for notifications)

but I am not sure if and how I should implement the unregister 's removeObserver command, because applicationDidReceiveMemoryWarning is not available for the AppDelegate.

  • Is DidReceiveMemoryWarning visiting all the viewControllers of the App?
  • Would it be sufficient to unregister in just one of my viewControllers ?

  • The application delegate does receive memory warnings:

    http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

    If it didn't, another option would be to use the notification center:

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(whatever:)
                   name:UIApplicationDidReceiveMemoryWarningNotification
                 object:nil];
    

    That all said, it seems to me that removing the observer on a memory warning is inappropriate. At what point will your reinstate it? But hey, if that's what Facebook recommends...

    链接地址: http://www.djcxy.com/p/66720.html

    上一篇: 滚动视图为多个文本字段不会工作

    下一篇: 我应该在哪个ViewController上实现FacebookSDK的removeObserver?