如何在特定时间自动从iOS通知中心删除推送通知? [英] How to automatically delete push notifications from iOS notification centre at a specific time?

查看:272
本文介绍了如何在特定时间自动从iOS通知中心删除推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用具有推送通知功能的Swift开发iOS应用.该应用程序通过推送通知(此处使用APNS)向用户发送生日提醒通知.

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.

有人可以建议我以哪种方式实现此解决方案?是否可以在没有任何用户交互的情况下从iOS删除通知?

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?

推荐答案

当应用程序被用户强行终止时的情况:

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
  }
} 

之后,当不需要在设备中显示通知时,您可以发送带有零徽章的静默通知,即使应用被强制终止,该通知也会清除徽章和通知 strong>由用户执行,但didReceiveRemoteNotification不会被调用,因为应用程序已终止. 静默推送通知的有效负载:

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

这篇关于如何在特定时间自动从iOS通知中心删除推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆