@@ -17,10 +17,10 @@ import {
1717
1818import JPushModule from 'jpush-react-native'
1919
20- const receiveCustomMsgEvent = 'receivePushMsg'
21- const receiveNotificationEvent = 'receiveNotification'
22- const openNotificationEvent = 'openNotification'
23- const getRegistrationIdEvent = 'getRegistrationId'
20+ // const receiveCustomMsgEvent = 'receivePushMsg'
21+ // const receiveNotificationEvent = 'receiveNotification'
22+ // const openNotificationEvent = 'openNotification'
23+ // const getRegistrationIdEvent = 'getRegistrationId'
2424
2525export default class App extends Component {
2626 constructor ( props ) {
@@ -226,50 +226,38 @@ export default class App extends Component {
226226 JPushModule . setupPush ( )
227227 }
228228
229- JPushModule . addReceiveCustomMsgListener ( map => {
229+ this . receiveCustomMsgListener = map => {
230230 this . setState ( {
231231 pushMsg : map . content
232232 } )
233233 console . log ( 'extras: ' + map . extras )
234- } )
234+ }
235235
236- JPushModule . addReceiveNotificationListener ( map => {
236+ JPushModule . addReceiveCustomMsgListener ( this . receiveCustomMsgListener )
237+ this . receiveNotificationListener = map => {
237238 console . log ( 'alertContent: ' + map . alertContent )
238239 console . log ( 'extras: ' + map . extras )
239- // var extra = JSON.parse(map.extras);
240- // console.log(extra.key + ": " + extra.value);
241- } )
240+ }
241+ JPushModule . addReceiveNotificationListener ( this . receiveNotificationListener )
242242
243- JPushModule . addReceiveOpenNotificationListener ( map => {
243+ this . openNotificationListener = map => {
244244 console . log ( 'Opening notification!' )
245245 console . log ( 'map.extra: ' + map . extras )
246246 this . jumpSecondActivity ( )
247- // JPushModule.jumpToPushActivity("SecondActivity");
248- } )
247+ }
248+ JPushModule . addReceiveOpenNotificationListener ( this . openNotificationListener )
249249
250- JPushModule . addGetRegistrationIdListener ( registrationId => {
250+ this . getRegistrationIdListener = registrationId => {
251251 console . log ( 'Device register succeed, registrationId ' + registrationId )
252- } )
253-
254- // var notification = {
255- // buildId: 1,
256- // id: 5,
257- // title: 'jpush',
258- // content: 'This is a test!!!!',
259- // extra: {
260- // key1: 'value1',
261- // key2: 'value2'
262- // },
263- // fireTime: 2000
264- // }
265- // JPushModule.sendLocalNotification(notification)
252+ }
253+ JPushModule . addGetRegistrationIdListener ( this . getRegistrationIdListener )
266254 }
267255
268256 componentWillUnmount ( ) {
269- JPushModule . removeReceiveCustomMsgListener ( receiveCustomMsgEvent )
270- JPushModule . removeReceiveNotificationListener ( receiveNotificationEvent )
271- JPushModule . removeReceiveOpenNotificationListener ( openNotificationEvent )
272- JPushModule . removeGetRegistrationIdListener ( getRegistrationIdEvent )
257+ JPushModule . removeReceiveCustomMsgListener ( this . receiveCustomMsgListener )
258+ JPushModule . removeReceiveNotificationListener ( this . receiveNotificationListener )
259+ JPushModule . removeReceiveOpenNotificationListener ( this . openNotificationListener )
260+ JPushModule . removeGetRegistrationIdListener ( this . getRegistrationIdListener )
273261 console . log ( 'Will clear all notifications' )
274262 JPushModule . clearAllNotifications ( )
275263 }
0 commit comments