In this recipe, we will discuss how to get notified when the application's state changes outside the scope of the UIApplicationDelegate
implementation.
Perform the following steps:
Enter the following fields in the
NotifyStatesAppViewController
class:private NSObject appDidEnterBackgroundObserver, appWillEnterForegroundObserver;
Create the following methods:
private void AddNotificationObservers() { this.appDidEnterBackgroundObserver = UIApplication.Notifications.ObserveDidEnterBackground((s, e) => Console.WriteLine("App did enter background! App state: {0}", UIApplication.SharedApplication.ApplicationState)); this.appWillEnterForegroundObserver = UIApplication.Notifications.ObserveWillEnterForeground((s, e) => Console.WriteLine("App will enter foreground! App state: {0}", UIApplication.SharedApplication.ApplicationState)); } private...