标签:json push 开发者 bug 推送 reg try err tap
1. 首先得在极光注册开发者帐号: 附上极光官网连接https: //www.jiguang.cn/
2. 创建好帐号后点进进入极光开发者服务》》 创建应用
3. 创建好应用会生成一个AppKey(后面需要), 到这里还没完, 切记点击下方的完成推送设置按钮
4. 点击后在推送设置里填写应用包名, 一定要和android项目包名一致, 否则拿不到注册id( android包名可以在cordova项目下platforms\ android\ app\ src\ main的AndroidManifest文件里查看, 这里要注意一点7 .0 版本前是在 platforms / android的的AndroidManifest文件里查看)
5. 在cordova根目录下安装推送插件( cordova add plugin jpush - phonegap - plugin--variable APP_KEY = 上文提到的AppKey), 极光上的appkey值
6. 插件安装好后就是调用了, 在vue根目录下src文件夹下的app.vue调用以下方法
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("jpush.receiveRegistrationId", function (event) {
console.log("receiveRegistrationId" + JSON.stringify(event));
}, false);
initJPush();
}
function initJPush() {
if (‘JPush‘ in window) {
console.log(‘initialize JPush...‘);
try {
window.JPush.init();
window.JPush.setDebugMode(true);
window.setTimeout(() => {
window.JPush.getRegistrationID((data) => {
console.log(data);
console.log(‘JPush initialize successful...‘);
});
}, 1000);
if (device.platform != "Android") {
window.JPush.setApplicationIconBadgeNumber(0);
}
} catch (exception) {
console.log(exception);
}
} else {
console.error(‘JPush is not exist...‘);
}
}
标签:json push 开发者 bug 推送 reg try err tap
原文地址:https://www.cnblogs.com/alantao/p/12496471.html