在 ionic3 中实现本地通知的问题

Issue on implementing local notifications in ionic3

我正在尝试向我的应用添加通知,但似乎没有任何效果。 我已经在应用程序模块以及我正在实施通知的页面中添加了导入。我希望看到通知,但点击按钮后什么也没有出现。

import { LocalNotifications } from '@ionic-native/local-notifications';

   play(){
       this.localNotifications.schedule({
                id: 1,
                text: 'Hello there',
                data: 'notified'
        });
   }

按钮代码:

  <button class="login-button" ion-button round color="secondary"(click)="play()">NOTIFICATION</button>

假设您安装和配置正确,请尝试以下步骤

步骤#1 ionic cordova 插件添加 cordova-plugin-local-notification npm 安装@ionic-native/local-notifications

步骤 # 2 您还需要将插件添加为 src/app/app.module.ts

中的提供程序
 providers: [
    StatusBar,
    SplashScreen,
    LocalNotifications,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]

可能是你忘记添加 app.module

步骤#3

Import { LocalNotifications } from '@ionic-native/local-notifications/ngx';


constructor(private localNotifications: LocalNotifications) { }

...


// Schedule a single notification
this.localNotifications.schedule({
  id: 1,
  text: 'Single ILocalNotification',
  sound: isAndroid? 'file://sound.mp3': 'file://beep.caf',
  data: { secret: key }
});