ebi ebi - 2 months ago 13x
Objective-C Question

Dismissing iOS push notifications remotely

The Gmail app for iOS is able to receive push notifications while the app is not running (as most email apps do).

However, it is also able to clear all Gmail push notifications from the device when the unread count of the user's Inbox becomes zero, even if the app is not running.

Here is an example sequence:
1. Receive a new email in your Gmail account.
2. The iOS device displays a notification for the new message.
3. Go to the Gmail website and open the message (marking the message as "read").
4. The notification on the iOS device is dismissed.


[[UIApplication sharedApplication] scheduledLocalNotifications]
only provides local notifications, i.e. those that were created within the iOS app itself.

As far as Apple's documentation for APNS describes, there is no way to remotely launch an app into the background, and there is no way to dismiss a remote notification.

So, how does the Gmail iOS app make this work?


I was able to clear all of my push notifications as well by pushing this payload, using Parse. I'm guessing as long as you supply content-available and badge, you should be able to do the same. I didn't have to write any other code in the AppDelegate, but I did have to turn on push notifications in the projects target capabilities.

curl -X POST \
-H "X-Parse-Application-Id: xxxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
       "data": {
         "content-available": "1",
       "where": {"something":"something_else"}
     }' \