1、查看ionic项目包名。
%home%\config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.xxxx.xxxx"
2、注册极光推送,创建一个APP, 设置包名为步骤1的结果。
3、在极光官网,查询刚才创建应用的APPKey。执行如下命令:
cd your_ionicproject_root
$ cordova plugin add Your_Plugin_Path --variable APP_KEY=your_jpush_appkey
$ npm install --save @jiguang-ionic/jpush
4、打开你的应用,添加代码:
\app\app.module.ts:
import { JPush } from '@jiguang-ionic/jpush';
...
providers: [ /*配置服务*/
... ,
JPush,
...
\app\app.component.ts
...
import { JPush } from '@jiguang-ionic/jpush';
...
export class MyApp {
rootPage:any = LoginPage;
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);
});
}
问题:
安装后,Android项目找不到代码:
原因:
代码文件路径不对:
多了一层APP
解决:
找到插件中的配置文件,修改一下targetdir:
jpush-phonegap-plugin\plugin.xml:
<source-file src="src/android/JPushReceiver.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushEventReceiver.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
更改为:
<source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
<source-file src="src/android/JPushEventReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
懒得重新安装,直接把代码复制了一下。
说明:关于代码目录问题,插件readme里有说明:
>注意:插件从 v3.4.0 开始支持 cordova-android 7.0.0,因 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。
查看本机 cordova-android版本:
$ cordova platforms
Installed platforms:
android 6.2.3