IOS extension - detect changes in extension status (Background / Foreground)

I have an extension for iOS8. The service uses OAuth for authentication. The login information that I use for the extension is shared with the container.

The problem is this:

When I am in the extension, the application switches to and leaves the container application, and then the application switches back to the host application containing the extension. How do I know if an extension has just appeared? The extension relies on certain information that must be present in the shared database between the container and the extension, but the data is deleted when the application exits.

I tried registering for various “application notifications” such as UIApplicationDidBecomeActiveNotification. However, as expected, they are not called for extensions.

How can I determine when the state of an extension changes so that I can make my extension more reliable when it reappears?

+5
source share
2 answers

Cm

NSExtensionContext.h 

In iOS 8.2, a number of notifications have been added for use for extensions:

 NSExtensionHostDidBecomeActiveNotification NSExtensionHostDidEnterBackgroundNotification NSExtensionHostWillEnterForegroundNotification NSExtensionHostWillResignActiveNotification 
+1
source

The viewDidAppear:animated: method of your main view controller class should be called every time you re-enter the extension. When you are about to leave, call viewWillDisappear:animated:

0
source

Source: https://habr.com/ru/post/1204127/


All Articles