Search code examples
iosswiftnotificationskillbackground-fetch

Setting daily local notifications when app is killed


I am making an "health" app that sends daily notifications to the user. The number of notification per day depends on the current day (for instance day 2 from first use) and the "health" exercice duration also depends on the current day (i send another notification after that time to notify the user that the exercice is over).

Knowing that we cannot plan more than 64 notifications I tried the following : 1. Setting up notifications for current day and next day when the user selects its app parameters and then 2. program next days notifications every days with background fetch (no matter how often as long as it is at least once a day).

However this doesn't work as if the user kills the app from the multitask list the background fetch will not be executed.

Is there anyway to plan my "next day" notifications without forcing the user to open the app to do so ? The idea is that the user can follow the program without having to open the app on each day or so.

I've seen that silent push notifications (does that allow to run code without having to open the app ?) or pushkit could do the trick but my app is not an VoIP app and could therefore be rejected...

Does anyone have a solution to this problem ?

Thank you very much for your answers.


Solution

  • You don't need VoIP to send a silent push notification. VoIP apps do have silent pushes and they are "superior" to regular silent pushes because they are delivered to the app even if the user has killed the app, which is not the case for a regular silent push.

    The downside of a silent push is that there are several situations when it will not be delivered to the app: - the user can disable them - the user has terminated the app - there is a lengthy active phone call at the moment the push is sent - the device might be offline - etc. etc.

    Therefore a silent push cannot be used to make sure you app runs every day.

    In your case, as it ultimately is the user who is being notified, is it possible for the server to send a user directed push to them? I mean might the server have the information available to know what to put into the notification content? (A user directed push is still delivered to the user even if the user has terminated the app).

    If the server does not have this information, then another thing to consider is push extensions. A push extension enables a user-directed push to be intercepted and its content altered/updated before it is displayed to the user. This way you would be ensuring the push notification displayed to the user every day even if the app has been terminated (though still subject to the fact that the user can disable notifications for the app). This can be tricky though, as a push extension is not a full part of your app, its separate, though the app and extension can share the underlying data if its stored in a group.

    So everyday your server could send a user-directed push, this gets intercepted by your extension, your extension runs and determines what the content of the push should be, then the push is displayed to the user.

    These are some options, can't say which if any is correct for you as only you know the precise details of your requirements.