4

How do I do this in Xamarin iOS?

ViewDidAppear is not called when opening app from background

The link below mentions the OnActivated method for Xamarin in the AppDelegate, but how do I subscribe my ViewController so it knows when the app comes from the background?

https://forums.xamarin.com/discussion/10594/where-is-applicationdidbecomeactive-in-xamarin-ios

Community
  • 1
  • 1
LampShade
  • 2,675
  • 5
  • 30
  • 60

1 Answers1

9
    NSObject notificationObserver = NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.DidBecomeActiveNotification, DoStuff);

    private void DoStuff (NSNotification a_notification)
    {
        // DO STUFF HERE
    }
LampShade
  • 2,675
  • 5
  • 30
  • 60
  • Where did you end up putting this? I keep getting an error that notificationObserver is assigned but its value is never used. – NorCalKnockOut Dec 12 '16 at 23:35
  • @NorCalKnockOut I store my notificationObserver as a class level property and then on Dispose of the view controller I remove it: NSNotificationCenter.DefaultCenter.RemoveObserver (this.notificationObserver); But the critical part is the NSAction you pass in so it runs your code when that event fires. In my case above it was "DoStuff" – LampShade Dec 13 '16 at 22:26