Notification Service Extension Lifecycle

Viewed 710

I have a question about Notification Service Extension Lifecycle, I have searched but I cant find a suitable answer for my question. The question is what happen when new notification come when old notification is in processing (not called contentComplete yet)?

From my testing, it will end the old process and start new processing with newer notification, and user will miss old notification, with all data that is not saved yet. Is that true?

1 Answers

I'm not absolutely positive but based on Signal's notification service extension code found here, what you're saying is correct. The way they solve it is as such:

// The lifecycle of the NSE looks something like the following:
//  1)  App receives notification
//  2)  System creates an instance of the extension class
//      and calls this method in the background
//  3)  Extension processes messages / displays whatever
//      notifications it needs to
//  4)  Extension notifies its work is complete by calling
//      the contentHandler
//  5)  If the extension takes too long to perform its work
//      (more than 30s), it will be notified and immediately
//      terminated
//
// Note that the NSE does *not* always spawn a new process to
// handle a new notification and will also try and process notifications
// in parallel. `didReceive` could be called twice for the same process,
// but will always be called on different threads. To deal with this we
// ensure that we only do setup *once* per process and we dispatch to
// the main queue to make sure the calls to the message fetcher job
// run serially. 

Make sure you see the rest of their code

Related