The application generates a token, sends it to the server, which registers it with itself. Then the server sends a message to the token and then the task of the mobile application is to intercept this message and, depending on the content, insert an image. Can this be done in the UNUserNotificationCenterDelegate framework UNUserNotificationCenterDelegate in the func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) or you need to be func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) or you need to be func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) . And if you can do a little blood, then how to do it? Here is the method, the problem is that this completionHandler calls the method indefinitely, and without it the message is not shown when the application is active. I will be glad to any hint, new to Swift, for the time being just trying to figure it out. Thank you in advance!
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { let notificationContent = notification.request.content let modifiedNotificationRequest = createMyNotificationRequest(from: notificationContent) center.removeAllPendingNotificationRequests() center.add(modifiedNotificationRequest) { (error) in if let error = error { print("Failed to send notification \(error.localizedDescription)") completionHandler(.alert) } } completionHandler(.alert) }