How to update body of repeated local notification in iOs 10?

北战南征 提交于 2019-12-10 17:35:32

问题


I created a local notification with Swift 3. The problem is that I want to change the body of local notification.

For example:
- There are 15 left issues.
20 minutes later:
- There are 10 left issues.

Can anybody help me, please?


回答1:


After research I can almost confirm that it is not possible to update the repeated notification without app being foreground.

When you schedule a repeated push notification, the title and body is already set. In order to change the tile and body we will need to catch notification. However, according to this answer, notification service extension only works for remote notification but not local notification.

SO... How to achieve this using work arounds?

I can think 2 ways to do this.

  1. Schedule approx 60 notification manually and preset the title and body. However, in your case, it is still not possible because you will never know how many issues left after 20 mins?? If you can pre-calculate, then you can use this solution. The disadvantage for this is it can only schedule for 64 local notifications and each time when push a local notification it creates a new delivered notification stay in the system which will spam user's notification center.

  2. The second way is to use Notification Content Extension. NOTE: You can still not modify the title and body for the notification delivered. However, you can create a custom screen when user force touch the notification bar. Maybe the subtitle can be something like force touch to see how many issues left and implement a custom screen to show the number of issues when user force touch on it.

I am still experiment on this. There's one more option that I want to suggest is you can always do a remote push notification if issue number changes, which might be a better user experience in your case instead of pushing a repeated one every 20 mins.


Useful Reference

Here is a tutorial I found useful for Notification Content Extension.

To understand more, here is a link to WWDC of introducing notification service extension and notification content extension.




回答2:


I believe you can use Notification Content Extension. You kinda have much more freedom since you are working with a view controller. I would use that!



来源:https://stackoverflow.com/questions/47507657/how-to-update-body-of-repeated-local-notification-in-ios-10

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