diff --git a/src/page/NotificationPage.js b/src/page/NotificationPage.js index 57fc5ac..39875e6 100644 --- a/src/page/NotificationPage.js +++ b/src/page/NotificationPage.js @@ -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; diff --git a/src/util/push.js b/src/util/push.js index 53a910e..4deea1c 100644 --- a/src/util/push.js +++ b/src/util/push.js @@ -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, } \ No newline at end of file