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

眉间皱痕 提交于 2019-12-10 21:45:19

问题


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?

Thanks in advance.


回答1:


@dm_mobile Your question is 100% valid.


In order to remove the specific notification from the Notification center automatically, - you can't do that from the iOS side, until and unless user interact with that notification - But, you can do that from the server side, let me tell you how


How to remove notification from the notification center programmatically? When server send you any notification via APNS server using the APNS endpoint, the APNS will return you some data as a payload, you will get the notification identifier as a apns-id key in the response header

Store that apns-id value in your database table at the server side.

At the end of day or with specific condition criteria, you can delete that notification from the device's notification center by sending another request to APNS by Passing the apns-id value in the request header.

Skype is doing the same thing.

Read this for more details: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW1



来源:https://stackoverflow.com/questions/55646178/how-to-automatically-delete-push-notifications-from-ios-notification-centre-at-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!