I am very confused about searching online for handling push notifications on iOS. AFAIK if you appoint a delegate
UNNotificationCenter then the method
userNotificationCenter(_:didReceive:withCompletionHandler:) is called when the user presses the alert. What’s more, if you use silent alerts, then the method
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)`Kalles. But it does not suit my needs, because I want to be notified before the user has the chance to press alert and update my data in the background, so that the user will see the “latest”
I saw several places that I do not want to send delegates to
application(_:didReceiveRemoteNotification:fetchCompletionHandler:) called instead, even twice, but it does not work for me: https://stackoverflow.com/questions/64172345/application-didreceiveremotenotificationfetchcompletionhandler-is-not-called.
Does this mean that it is not possible to handle the notification before the user presses it? Is it a good practice to always send two notifications at the same time: one notification (so that the user will see the notification list) and one silent (so that the app can update data)?
Interestingly, after installing the app several times, it started working. I put in
UNNotificationCenterdelegate and it works like this:
The app is in the background, the server sends a message with
The system displays alarm and
application(_:didReceiveRemoteNotification:fetchCompletionHandler:)is called so I can retrieve new data.
User cranes on standby,
userNotificationCenter(_:didReceive:withCompletionHandler:)called so I can navigate to a specific view.
Is there a proper way to handle push alerts with data payload?