ionic4学习笔记(五)--消息推送JPush

1.在极光官网注册、登录、创建应用

极光推送官网地址
ionic4学习笔记(五)--消息推送JPush_第1张图片
应用名称要与config.xml一致
ionic4学习笔记(五)--消息推送JPush_第2张图片

2.安装插件

cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey
//your_jpush_appkey是应用信息的AppKey
npm install --save @jiguang-ionic/jpush

插件github链接
ionic4学习笔记(五)--消息推送JPush_第3张图片

3.修改配置文件

在app.module.ts文件中引入:

import { JPush } from '@jiguang-ionic/jpush/ngx';
 providers: [
    ...
    JPush,
   ...
  ]

在app.component.ts文件中引入

import { JPush } from '@jiguang-ionic/jpush/ngx';
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private jpush:JPush
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      this.jpush.setDebugMode(true);
      this.jpush.init();
    });
  }
}

在JPushPlugin.java文件中引入包名
ionic4学习笔记(五)--消息推送JPush_第4张图片
一定要引入包名,不然会报错(真正血与泪的教训)

Failed to post notification on channel "JPush_Notification" 

ionic4学习笔记(五)--消息推送JPush_第5张图片

4. 打包安装到手机、在极光官网填写推送信息发送

ionic4学习笔记(五)--消息推送JPush_第6张图片

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