Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 218
Duc Nguyen Avatar asked Nov 27 '17 09:11

Duc Nguyen


People also ask

How many local notification are there in iOS?

Local notification volume is limited to 64 notifications per iOS app per day, which can be constraining if notifications are vital to your app's functionality and you have a large user base.

What is local notification in iOS?

Use local notifications to get the user's attention. You can display an alert, play a sound, or badge your app's icon. For example, a background app could ask the system to display an alert when your app finishes a particular task. Always use local notifications to convey important information that the user wants.


1 Answers

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.

enter image description here

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.

like image 76
nuynait Avatar answered Sep 23 '22 16:09

nuynait