Skip to content

iOS - Identifying the trigger of iOS Remote notifications callback #56

Open
@eladmoshe

Description

@eladmoshe

Hi,

This is a question rather than an issue.
TL;DR - In application:didReceiveRemoteNotification I want to identify when the callback was triggered by user tapping the notification vs. the callback being called by the OS upon arrival of a notification.

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)?

I tried querying the applicationState. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions