问题
Is there any way (in PhoneGap) I can schedule events or callbacks to happen at designated times each day?
I guess I'm looking for something like Android AlarmManager, so that I can trigger some notification each day at a certain time, that would then prompt the user to launch my app.
回答1:
You could use this:
https://github.com/katzer/cordova-plugin-local-notifications.git
It allows you to use local notifications of the device.
Once you have installed this plugin you gain access to the window.plugin.notification.local
variable. You can then run:
window.plugin.notification.local.add({
date: new Date(),
message: 'Your notification message'
});
This will set a notification to appear on the users device at the specified date.
I have used this with Moment JS to handle my timed notifications.
来源:https://stackoverflow.com/questions/21115844/can-i-schedule-events-callbacks-at-specified-times-each-day-in-phonegap