离子2本地通知未显示

时间:2017-12-31 22:47:22

标签: cordova ionic-framework ionic2

我第一次使用ionic 2本地通知。我跟着这个YouTube tutorial

当我在Xcode中测试我的应用程序时,我在下面收到一条警告消息并且通知消息未显示...不确定原因。

  

警告:未知财产:在

我已经安装了

  

ionic cordova plugin add de.appplant.cordova.plugin.local-notification

     

npm install --save @ ionic-native / local-notifications

并在 src / app / app.module.ts

中添加了该插件作为提供程序

我有以下代码:

home.html的:

<button ion-button (click)=myNotifications()>Test</button>

app.module.ts

import { Component } from '@angular/core';
import { NavController, Platform, ActionSheetController, AlertController } from 'ionic-angular';
import { ScreenOrientation } from '@ionic-native/screen-orientation';
import { LocalNotifications } from '@ionic-native/local-notifications';


    export class HomePage {

      constructor(public navCtrl: NavController,
                  public platform: Platform,
                  private screenOrientation: ScreenOrientation,
                  private localNotifications: LocalNotifications,
                  public alertCtrl: AlertController ) {

                    this.platform.ready().then((ready) =>{
                      this.localNotifications.on('click', (notification, state) => {
                        let json = JSON.parse(notification.data);

                        let alert = this.alertCtrl.create({
                          title: notification.title,
                          message: json.fullMsq
                        });
                        alert.present();
                      });
                    });
      }

      myNotifications() {

        this.localNotifications.schedule({
          id: 1,
          title: 'ABC Meeting Notification',
          text: 'ABC Meeting will start in 20 mins',
          at: new Date(new Date().getTime() + 20*60*1000),
          data: { fullMsq: 'this is the full notification message' }
        })
      }

    }

1 个答案:

答案 0 :(得分:1)

参考通知演示: https://github.com/husainsr/Ionic3_Notification 可能它证明对你有帮助。