ionic4本地通知Local Notifications

本地通知Local Notifications

1.安装插件

ionic cordova plugin add cordova-plugin-local-notification
npm install @ionic-native/local-notifications

2.在app.components.ts中引用
ionic4本地通知Local Notifications_第1张图片

import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
s
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss']
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private localNotifications: LocalNotifications,
  ) {

    this.initializeApp();
  }

  initializeApp() {
    this.testStatus();
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }

  testStatus() {

    this.localNotifications.schedule({
      id: 1,
      title: '通知标题',
      text: '这是显示通知栏的内容',
      // icon: '',
      trigger: { at: new Date(new Date().getTime() + 9000) },
    });
  }

}

目前在android上测试不支持android9.0版本

你可能感兴趣的:(混合APP)