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

View file

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