Understanding the iMessage app life cycle

An iMessage app lives inside the Messages app, just like you would expect from an extension. As mentioned before, iMessage apps are a special kind of extension, which makes them behave a lot like apps even though they are still extensions at their core.

The main view controller for an iMessage app must always be a subclass of MSMessagesAppViewController. You can't have a primary view controller that is not a subclass of this class. When the user navigates to your extension through the iMessage apps drawer, this view controller is added where the keyboard would normally be placed. This size for the extension is called compact mode.

When the Messages framework instantiates your extension, the willBecomeActive(with:) method is called, followed by didBecomeActive(with:). These methods are called after viewDidLoad() in the view controller life cycle, but before viewWillAppear(_:). When it's time to dismiss your extension, the viewWillDisappear(_:) and viewDidDisappear(_:) life cycle methods are called. Next, willResignActive(with:) and didResignActive(with:) are called.

Once the resignation methods are called, the process for your iMessage app is killed shortly thereafter. You do not get any time to do work in the background. This is also true for other extension types. Again, even though Messages extensions behave a lot like apps, they're not.

There are two more methods you should know about for now. These methods are called whenever your iMessage app is transitioning from one display mode to another. The display mode is changed whenever the user expands the iMessage app by dragging the handle that is shown above your extension's view.

You can also trigger this transition from code by calling requestPresentationStyle(_:). The life cycle methods that get called when the extension changes its size are willTransition(to:) and didTransition(to:). The first method is called right before the transition occurs, the second is called right after.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset