Search code examples
xamarin.iosobsolete

MonoTouch NSNotificationCenter.DefaultCenter.AddObserver now obsolete?


I'm just wondering what the modern equivalent of:

NSNotificationCenter.DefaultCenter.AddObserver("UIDeviceOrientationDidChangeNotification", receivedRotate);

would be. It says its obsolete and that I should use AddObserver, but I'm not sure what to use for the IntPtr context var.


Solution

  • You don't need the IntPtr variant, if you read the Obsolete method it says:

    "Use AddObserver(NSString, Action) instead"

    So what you want is

    NotificationCenter.DefaultCenter.AddObserver (UIDevice.OrientationDidChangeNotification, receivedRotate);