Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically delete push notifications from iOS notification centre at a specific time?

I am developing an iOS app using Swift which has push notification feature. The app sends Birthday reminders notifications to the users via push notifications (APNS used here).

Currently, the push notification remains in the device's notification center until the user taps on that notification or opt to clear it from the device.

Now I am looking for a way to automatically delete that push notification at the end of every day as there is no need of showing past day's birthday notifications in the device.

Can someone suggest me a solution that in which way I can implement this? Is it possible to delete notification from iOS without having any user interaction?

like image 502
dm_mobile Avatar asked Apr 12 '19 07:04

dm_mobile


People also ask

How do I turn off notifications for certain times on my iPhone?

On iOS, select the Settings icon. Scroll to Do Not Disturb, then toggle the Scheduled slider. This will open a screen that lets you select times of day when your phone will not ring, vibrate, or light up for notifications.

Can you set notifications for certain times iPhone?

Schedule a notification summaryGo to Settings > Notifications > Scheduled Summary, then turn on Scheduled Summary. Under Apps in Summary, select the apps that you want to include in your notification summary. Under Schedule, tap the Add button to add a new schedule or the Remove button to remove a schedule.

Can you set app notifications for certain times?

On Android, open Settings and tap Apps and All apps, then pick an app and choose Notifications to set the desired rules. You can turn notifications on or off from here and in some cases choose which type of notifications to silence.

Can you clear all iPhone notifications at once?

Handle a notification you receive while using another app: Tap to view it, then swipe up to dismiss it. Clear notifications: Swipe left on a notification or group of notifications, then tap Clear or Clear All.


1 Answers

This for scenario when the app is forcefully terminated by the user :

First of all send nonzero badge when you want to send Birthday reminders notifications to the users via push notifications , For example :

 {
  "aps": {
    "alert": {
      "title": "Hey! Urgent Reminder",
      "body": "Do not forget my wife SURPRISE BIRTHDAY PARTY"
    },
    "badge": 1
  }
} 

After that , When there is no need of showing notifications in the device , you can send silent notification with zero badge that will clear badge and notifications even if app is forcefully terminated by the user but didReceiveRemoteNotification will not called because app is terminated. payload for silent push notification :

 {
   "aps" : {
      "content-available" : 1,
        "badge" : 0,
        "Priority" : 10
   }
}

After send that payload will automatically clear badge and delete push notification from Notification Center.

Note that if badge was zero before sending silent notification , will not clear notifications.

https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

like image 54
mhammad alkhalaf Avatar answered Oct 02 '22 12:10

mhammad alkhalaf