5

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?

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
Duc Nguyen
  • 61
  • 3
  • you can check out this post. https://stackoverflow.com/questions/41768568/ios-overriding-local-notifications – Kumar Reddy Nov 27 '17 at 10:02
  • 2
    Sorry but it doesn't solve my issue – Duc Nguyen Dec 04 '17 at 07:49
  • I want to do the similar things. Have you found a solution to it? @KumarReddy that post has nothing related to the question. – nuynait Dec 22 '17 at 04:48
  • Why not related to the question. The purpose is tht you need to replace the body of the sent local notification. To do that they have mentioned possible ways. Why did you feel that it is not related? – Kumar Reddy Dec 22 '17 at 04:52
  • Because the example is after 20 minutes push notification of "There are 10 left issues" and it is very possible that user doesn't active the app in between. So it means it needs to update the repeated notification with app not active. :) That post is about update notification with button pressed. – nuynait Dec 22 '17 at 05:29
  • Still no answer to this...? :/ –  Jan 12 '19 at 22:03

2 Answers2

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.

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.

Community
  • 1
  • 1
nuynait
  • 1,912
  • 20
  • 27
0

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!

Maz
  • 245
  • 3
  • 11