1、在极光后台添加app得到appKey,包名需要和ionic包名一致。ionic 工程中加入jpush插件
通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+:
cordova plugin add jpush-phonegap-plugin --variable APP_KEY=appKey
或直接通过 url 安装:
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable APP_KEY=appKey
2、安装 @jiguang-ionic/jpush 包
npm install --save @jiguang-ionic/jpush@1.0.2
**# npm install --save @jiguang-ionic/jpush@2.0.0 for ionic4+**
3、安装 @jiguang-ionic/jpush 以后,在 app.module.ts 文件中,导入,然后添加到 服务(providers)中。
import { JPush } from '@jiguang-ionic/jpush';
...
providers: [
...
JPush,
...
]
4、在app.component.ts 初始化
import { JPush } from '@jiguang-ionic/jpush';
constructor(platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
jpush:JPush) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
jpush.init();
jpush.setDebugMode(true);
});
}
官网地址:https://github.com/jpush/jpush-phonegap-plugin
可能出现的问题
[JCoreGlobal] JCore .so file do not match JCore .jar file in the project, Failed to init JCore
找不到so文件,解决方法为:在build.gradle 中 设置jni路径
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
}
}