Reputation: 1374
I have a Cordova app for Android and iOS which logs in a sqlite database when the user last opened the app. This data is also sent to a remote storage.
I want to alert the user that they haven't opened the app for x number of days and to do so.
For Android, that was pretty simple; I just scheduled a repeating AlarmManager, query the database and show a notification if the last open date was more than a day ago.
It doesn't appear to be so simple for iOS as, other than scheduled Local Notifications, there doesn't seem to be long running background tasks available, or anything similar to Broadcast Receiver.
Am I correct in thinking that for iOS, I will need to do the calculation of how long it has been since a user last opened the app within my remote datastore server, and then send the alert to the app via a push notification?
Or, is it possible to schedule a local notification and then have that do some calculations to decide whether to show itself?
Upvotes: 1
Views: 1123
Reputation: 3101
The task is simple for both platforms by using local notification:
When the user starts or resumes the app, you do a datetime calculation and a predefinition when the notification should popup. That's it.
On next app start/resume, you remove the old notification and make a new setting for the next one.
I'm doing a similar task with this plugin: https://www.npmjs.com/package/de.appplant.cordova.plugin.local-notification
Upvotes: 2