1.ionic start myapp tabs
//下载插件
2. git clone https://github.com/jpush/jpush-phonegap-plugin.git
获取之后修改
3.:添加极光的密匙文件
//首先
cordova plugin add jpush-phonegap-plugin --variable APP_KEY=a0da4fec58aee243d5878a9e
修改JAVA.config.java
import com,you,name.R;
4.
第三步安装 jpush device
npm install --save @jiguang-ionic/jpush
npm install --save @ionic-native/device
删除自己的版本
//添加项目需要的版本
npm uninstall -g cordova@
npm install -g cordova@7.1.0
5.ionic cordova platform add android
//添加平台
6.ionic cordova build android --release
ionic cordova build android 测试
//打包APK
//打包问题出现乱码 自己在从新另存为一下
import { JPush } from '@jiguang-ionic/jpush';
import { Device } from '@ionic-native/device';
public jpush: JPush, public device: Device
//极光推送
this.devicePlatform = device.platform;
document.addEventListener('jpush.receiveNotification', (event: any) => {
var content;
if (this.devicePlatform == 'Android') {
// alert(JSON.parse(event)['cn.jpush.android.EXTRA'])
} else {
content = event.aps.alert;
}
// alert('Receive notification: ' + JSON.stringify(event));
}, false);
document.addEventListener('jpush.openNotification', (event: any) => {
var content;
if (this.devicePlatform == 'Android') {
if (event.extras['cn.jpush.android.EXTRA'].page) {
this.navCtrl.push(AboutPage);
}
} else { // iOS
if (event.aps == undefined) { // 本地通知
content = event.content;
} else { // APNS
content = event.aps.alert;
}
}
// alert('open notification: ' + JSON.stringify(event));
}, false);
document.addEventListener('jpush.receiveLocalNotification', (event: any) => {
// iOS(*,9) Only , iOS(10,*) 将在 jpush.openNotification 和 jpush.receiveNotification 中触发。
var content;
if (this.devicePlatform == 'Android') {
} else {
content = event.content;
}
//alert('receive local notification: ' + JSON.stringify(event));
}, false);
//获取ID
jpush.getRegistrationID()
.then(rId => {
});