Suppose you implement email client application. When a new mail is received, a notification should be displayed, and the app should pull the new mail ASAP. When the user taps the notification in the notification center, the app should display the new mail. However, if he opens the application directly (not through the notification) he should see the list of mails already updated with the latest data.
Ideally, the app would have a callback called upon arrival of a notification with {content-available:1}
for updating the data, and another callback when the user clicks the notification.
However, if the app implements application:didReceiveRemoteNotification:fetchCompletionHandler:
the same callback might be called twice - once immediately when the notification arrives, and again if the user clicks the notification in the notification center.
So, when the callback is triggered, how should the app know if it should navigate to the new mail (when the user taps the notification) or fetch the data (called by the system)?
Update - I tried querying the applicationState
according to this answer. This doesn't help as when the user opens the control center and a notification is received (but not tapped), the application is in inactive state, same as it is when the user taps the notification.