3.1.18之前云打包一直正常,但是升级到 3.1.22后,云打包会卡在 登录页面,用自定义基座查看 token和 push cid,都是null。
原代码如下。
``onLaunch: function() {
console.log('App Launch')
// #ifdef APP-PLUS
plus.screen.lockOrientation('portrait-primary');
let that=this
plus.push.addEventListener('click', that.pushNoticeClicked, false);
plus.push.addEventListener('receive', that.pushNoticeRecieved, false);
this.initPush(this);
// #endif
},
...
methods: {
claerBadge() {
// #ifdef APP-PLUS
this.$push.get = true
if (plus.os.name.toLowerCase() == 'ios') {
}
},
async initPush(that) {
console.log('start init push ...')
// #ifdef APP-PLUS
that.$push.platform = uni.getSystemInfoSync().platform;
try {
if (that.$push.platform === 'android') {
let result = await
permision.requestAndroidPermission("android.permission.READ_PHONE_STATE");
if (result === 1) {
console.log("client info =", plus.push.getClientInfo());
that.$push.pushCid = plus.push.getClientInfo().clientid;
uni.showLoading({
title: 'loading...'
})
while (!that.$push.pushCid || that.$push.pushCid == 'null') {
that.$push.pushCid = plus.push.getClientInfo().clientid;
}
uni.hideLoading();
console.info('push setup ready on', that.$push.platform, that.$push.pushCid);
} else if (result === 0) {
return;
} else {
}
} else {
let result = await permision.judgeIosPermission("push");
if (result) {
console.log("client info =", plus.push.getClientInfo());
that.$push.pushCid = plus.push.getClientInfo().clientid;
uni.showLoading({
title: 'loading...'
})
while (!that.$push.pushCid || that.$push.pushCid == 'null') {
that.$push.pushCid = plus.push.getClientInfo().clientid;
}
uni.hideLoading();
console.info('push setup ready on', that.$push.platform, that.$push.pushCid);
} else {
}
}
} catch (err) {
console.warn('fail to setup push!!!', err);
}
if (that.$push.pushCid == '' || pushTime >= 5) {
console.warn('push cid is null, retry...')
pushTime
setTimeout(function() {
that.initPush(that)
}, 1000);
return;
}
// #endif
},
使用一个延时获取方法,替换原方法,延时获取cid,不会白屏,但是仍然是得不到push cid
var clientid,
clientid_timer = null;
clientid = plus.push.getClientInfo().clientid;
console.log("000000000000000000000")
clientid_timer = setInterval(() => {
if(!clientid || null==clientid || "null" == clientid) {
clientid = plus.push.getClientInfo().clientid;
}else {
console.log("100100100100100100100100")
this.initPush(this);
clearInterval(clientid_timer);
}
}, 100);
0 个回复