完善 push

This commit is contained in:
mx1700 2019-07-28 21:00:46 +08:00
parent c0f9751b7f
commit 49c332d811
2 changed files with 13 additions and 15 deletions

View file

@ -83,7 +83,8 @@ export default class NotificationPage extends Component {
componentWillUnmount() {
this.loginListener.remove();
//todo:删除 push 事件注册,删除定时器
clearTimeout(this.tipTimer);
Push.removeReceiveNotificationListener(this.receiveNotification);
}
updatePushInfo() {
@ -108,9 +109,7 @@ export default class NotificationPage extends Component {
Push.init((msg) => {
console.log("push init: " + msg);
this.registerUser();
Push.addReceiveNotificationListener((msg) => {
this.restartTipTimer().catch((err) => console.log(err))
});
Push.addReceiveNotificationListener(this.receiveNotification);
})
}
@ -118,12 +117,14 @@ export default class NotificationPage extends Component {
Push.init((msg) => {
console.log("push init: " + msg);
this.registerUser();
Push.addReceiveNotificationListener((msg) => {
this.restartTipTimer().catch((err) => console.log(err))
});
Push.addReceiveNotificationListener(this.receiveNotification);
})
}
receiveNotification = (msg) => {
this.restartTipTimer().catch((err) => console.log(err))
};
async registerUser() {
const user = await Api.getSelfInfoByStore();
if (!user || !user.id) return;

View file

@ -32,15 +32,11 @@ function setAccount(uid, cb) {
}
function addReceiveNotificationListener(cb) {
XGPushModule.addReceiveNotificationListener((map) => {
console.log("[ReceiveNotification]", map);
cb(map);
});
XGPushModule.addReceiveNotificationListener(cb);
}
// XGPushModule.addReceiveOpenNotificationListener((msg) => {
// console.log("[addReceiveOpenNotificationListener]", msg)
//
// })
function removeReceiveNotificationListener(cb) {
XGPushModule.removeReceiveNotificationListener(cb)
}
@ -49,4 +45,5 @@ export default {
init,
setAccount,
addReceiveNotificationListener,
removeReceiveNotificationListener,
}