Disable iOS push notifications remotely

The Gmail app for iOS can receive push notifications while the app isnโ€™t working (as most email apps do).

However, it can also clear all Gmail notifications from the device when the user's unread incoming mail counter becomes zero , even if the application does not work .

Here is an example sequence: 1. Receive a new email in your Gmail account. 2. The iOS device displays a notification for a 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 rejected.

Note. [[UIApplication sharedApplication] scheduledLocalNotifications] provides only local notifications, ie those that were created in the iOS application itself.

As for Apple documentation for APNS , there is no way to remotely run the application in the background , and there is no way to reject the remote notification.

So how does the iOS app for Gmail work?

+5
source share
3 answers

I was able to clear all my push notifications by clicking this payload using Parse. I assume that while you supply content-available and badge , you should be able to do the same. I did not need to write any other code in AppDelegate, but I needed to include push notifications in the capabilities project goal.

 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", "badge":"0", "sound":"" }, "where": {"something":"something_else"} }' \ https://api.parse.com/1/push 
+5
source

IOS has a silent click feature that allows your application to wake up and update itself in the background after receiving a push-less push notification.

Session 713 at WWDC 2014 described this in detail:

Silent notifications are simply push data that is sent from your APN server, which instead of presenting a user notification, such as a warning or a sound or an icon on the screen, iOS, when it receives this push, instead wakes your application in the background to Your application may perform some background image processing or information processing.

In this case, your application selects content from the server. In this case, your application selects content from the server so that next time the user clicks on the icon of his application and brings it to the foreground, this information exists and is ready, so no one has to wait for the bootloader to complete, and all that.

0
source

Try if the icon number is already set,

 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; 

or try if not installed

 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; 

This will clear your push notifications and local notification.

0
source

Source: https://habr.com/ru/post/1213496/


All Articles