Reputation: 7677
Notification service extension (NSE) allows to process notifications in iOS app before showing them to the user (e.g., for message decryption):
class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// call content handler here when ready
}
override func serviceExtensionTimeWillExpire() {
// call content handler here with the best attempt
}
}
As I understand, for each notification a new instance of NotificationService is created, but all these instances can be in the same process that may share access to the database and other resources - iOS doesn't start a new NSE process for each new notification.
At some point iOS kills NSE process, and if database connection is not properly released, it results in the exception with 0xdead10cc exit code ("dead lock") that is visible to the users as an alert about the crash of the app in the background.
Is there a way to determine when iOS is about to kill NSE process to release the resources?
Upvotes: 1
Views: 325
Reputation: 37581
From your description, you make it sound as if you are thinking there can be several instances of the NSE active at once? That's not what happens, if the handset receives multiple pushes simultaneously, the OS keeps them in a queue and launches then closes, launches then closes, etc. the extension.
The extension gets terminated when you call contentHandler() to display the notification, or if you don't call than then after about 30 seconds the OS calls serviceExtensionTimeWillExpire(). In both cases the extension will be terminated (and if while it was running, the phone had received another push, then it'll be launched again)
Upvotes: 2