Ich erstelle eine Ionic 3-Anwendung und ich muss lokale Benachrichtigungen planen. Ich versuche nur, eine Testbenachrichtigung einzurichten, aber ich kann es nicht funktionieren lassen. Ich habe es in einem Emulator versucht, aber nichts passiert. Das LocalNotifications-Plugin wurde auch zu meiner app.module.ts-Datei hinzugefügt.Wie kann ich eine lokale Benachrichtigung in Ionic 3 senden?
Hier ist meine Typoskript-Datei importiert und Funktion:
import { Component } from '@angular/core';
import { NavController, NavParams, Platform, AlertController } from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
import * as moment from 'moment';
@Component({
selector: 'page-notification',
templateUrl: 'notification.html',
})
export class NotificationPage {
// Define the variables used in the view
notifyTime: any;
notifications: any[] = [];
// The constructor initializes the imports
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public platform: Platform,
public alertController: AlertController,
public localNotifications: LocalNotifications
) {}
testNotification() {
// The notification
let notification = {
id:1,
title: "test",
text: "I am tester ?",
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']
});
alert.present();
});
}
console.log("Notifications to be scheduled: ", this.notifications);
}
Ich kann sehen, das folgende Objekt in der Konsole übergeben worden:
every:"minute"
id:1
text:"I am tester ?"
title:"test"
Es ist immer noch etwas zu zeigen, wenn die Schaltfläche geklickt wird . Weißt du, was zu tun ist?
Ihre Lösung funktioniert, und ich glaube, ich tat, wie Gut. Anscheinend waren meine Plugins nicht richtig installiert. Wenn Sie Probleme haben, installieren Sie die Plugins in der Antwort und verwenden Sie die neueste Version des Ionic CLI. – krillebimbim
@krillebimbim auch ich bin konfrontiert "Fehler bei der Installation 'de.appplant.cordova.plugin.local-notification': CordovaError: Fehler beim Abrufen des Plugins cordova-plugin-app-event über die Registrierung". Fehler beim Installieren des Benachrichtigungs-Plugins in ionic 3. Sind Sie gleichgesagt? Wie hast du es gelöst? – Thakur