Right after I receive a notification I want to execute a background task. I'm using firebase to receive notification. I can receive notification successfully with 'UNUserNotificationCenter' in the AppDelegate file.
Now my goal is to send a "GET" - "PUT" request, right after I received a notification (only when the app is in background)
I saw the documentation about Background Tasks: https://developer.apple.com/documentation/backgroundtasks
But I can't found a way to execute a background task right after I receive a notification.
Is anyone has any suggestion about that? Thank you
Thank you for your answer. I made it work
In app delegate:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Here return .newData after you checked if you have any new data, or .noData in case of nothing to update.
// A request to the server can be made to check if new data are available for the app
completionHandler(UIBackgroundFetchResult.newData)
}
For those who are using firebase push notification, I use this: ["to" : token, "priority": "normal", "content_available": true]
for silent notification