我看得很远但我似乎无法通过本地通知插件在Ionic 3中找到任何回调函数的示例。通知工作正常,但我试图在每次通知后更改数据。这样下周的通知将有新的内容。
我可以获取新数据,但似乎无法更改已安排的通知。
Ionic version: 3.1.1
Node version: 6.10.0
我的notification-page.ts看起来像这样:
// This is where the data loads from the service.
// It happens when the view loads for the first time.
ionViewDidLoad() {
// Get the JSON data from our itemApi
this.itemApi.getItems().then(data => {
this.items = data;
let randomNumber = Math.floor(Math.random() * this.items.length)
// Select the random object an pass it to the oneItem object
this.oneItem = this.items[randomNumber];
});
}
testNotification() {
// The notification
let notification = {
id:1,
title: this.oneItem.word,
text: this.oneItem.description,
every: "minute"
};
this.notifications.push(notification);
if(this.platform.is('cordova')){
// Cancel any existing notifications
this.localNotifications.cancelAll().then(() => {
// Schedule the new notifications
this.localNotifications.schedule(this.notifications);
this.notifications = [];
let alert = this.alertController.create({
title: 'Notifications set',
buttons: ['Ok']
});
// Initializes the alert
alert.present();
// Creates a callback function on the schedule trigger - populates the notification with new data
this.localNotifications.on("schedule", function(){
// Get the JSON data from our itemApi
this.itemApi.getItems().then(data => {
this.items = data;
let randomNumber = Math.floor(Math.random() * this.items.length)
// Select the random object an pass it to the oneItem object
this.oneItem = this.items[randomNumber];
});
// The notification is created again in the callback
let notification = {
id:1,
title: this.oneItem.word,
text: this.oneItem.description,
every: "minute"
};
this.notifications.push(notification);
});
// Ends the callback function
});
}
}
// End of notification
我当前正试图使用我在文档中找到的on(" schedule")回调。但是,我似乎无法让它发挥作用。
你有什么建议吗?