安卓
環境:ionic3 + 極光

應用包名一定要與config.xml一致
ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey(這里為極光的appkey)
npm install --save @jiguang-ionic/jpush
注意:在android6.4和android7.0之后的文件結構有所不一樣。
因為我直接安裝最新,但是我android@6.4,所以需要搬下插件位置。
即可。
前端代碼:
1.在app.module.ts注冊插件
import { JPush } from '@jiguang-ionic/jpush';
2.在main.ts添加監聽事件
// 打開 document.addEventListener('jpush.openNotification', (event?: any)=>{ console.log('---------------jpush openNotification main----------------') console.log(JSON.stringify(event)) alert(JSON.stringify(event)) }, false); // 獲取自定義信息內容 document.addEventListener('jpush.receiveMessage', (event?: any)=>{ console.log('---------------jpush receiveMessage main----------------') console.log(JSON.stringify(event)) alert(JSON.stringify(event)) }, false); // 后台接受通知 document.addEventListener('jpush.receiveLocalNotification', (event?: any)=>{ console.log('---------------jpush receiveLocalNotification mainmain----------------') console.log(JSON.stringify(event)) alert(JSON.stringify(event)) }, false);
3本地通知
// jpush this.JPush.addLocalNotification(1, 'content', 'title', 1, 100, '{"data": "123"}');
ios
鑒於ios接觸很少,只是做零散的筆記
ios有3種證書,開發證書,生產證書,推送證書。我就讓同事拉我進開發者,我是只能查看和使用
然后一些Xcode設置
開啟與證書一直的相關設置
設置好debug
在ionicbuild后需要添加原生代碼來注冊,注冊成功才能接受通知,否則只能使用本地通知和自定義信息。
ionic cordova build ios
ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"
第一個為正常build,第二個有部分build成功,但是無法真機調試的解決方案之一。
最后,在AppDelegate.m添加代碼:這里在極光推送的ios文檔有
https://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/#_5
如果一切正常,就可以正常推送信息。
當出現這個錯誤的時候:
我的解決方法是:
原來的“New Build System”設置成“Legacy Build System”
在第一次接觸ios,很多各種證書問題,設置問題,所以就靠記憶回想記錄,各種零散,方便自己查看。
推送功能,在前台,后台的時候,都安卓和ios都可以接受到發送通知,自定義信息只能在前台接受到;
在debug的時候,關了app,ios依然可以接受到通知;安卓不行;據說,大的品牌例如qq,百度等等這些app假如了廠商的白名單,任務器關了也會有相關程序在;