【问题标题】:Issue on implementing local notifications in ionic3在 ionic3 中实现本地通知的问题
【发布时间】:2019-06-11 12:01:27
【问题描述】:

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

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>

【问题讨论】:

  • 你是在本机设备上测试这个吗?还是通过离子服务?
  • @Sergey Rudenko,我用的是真机

标签: cordova ionic3 angular5 localnotification


【解决方案1】:

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

第 1 步 离子cordova插件添加cordova-plugin-local-notification npm install @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 }
});

【讨论】:

    猜你喜欢
    • 2019-01-25
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多