Skip to content

Commit

Permalink
PushNotificationIOS: Use PushNotificationEventName as the key to stor…
Browse files Browse the repository at this point in the history
…e in the handler map

Summary:
If we are using the same handler for different events, e.g. both `notification` and `localNotification` use `_onNotification()` handler, the former listener stored in `_notifHandlers` would be overridden by the latter so it's impossible to remove the `notification` listener when we call `removeEventListener`.

This PR stores the listeners by using `pushNotificationEventName` (notification, localNotification, register or registrationError) as the key.

Use the same handler for `notification` and `localNotification`, both listeners will be removed when calling `removeEventListener`.
Closes #10776

Differential Revision: D4168722

Pulled By: hramos

fbshipit-source-id: d68581428d2acde314f7b5333feafe1ec7807159
  • Loading branch information
ianlin authored and Facebook Github Bot committed Nov 14, 2016
1 parent 015a497 commit e51cb34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Libraries/PushNotificationIOS/PushNotificationIOS.js
Expand Up @@ -258,7 +258,7 @@ class PushNotificationIOS {
} }
); );
} }
_notifHandlers.set(handler, listener); _notifHandlers.set(type, listener);
} }


/** /**
Expand All @@ -270,12 +270,12 @@ class PushNotificationIOS {
type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification', type === 'notification' || type === 'register' || type === 'registrationError' || type === 'localNotification',
'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events' 'PushNotificationIOS only supports `notification`, `register`, `registrationError`, and `localNotification` events'
); );
var listener = _notifHandlers.get(handler); var listener = _notifHandlers.get(type);
if (!listener) { if (!listener) {
return; return;
} }
listener.remove(); listener.remove();
_notifHandlers.delete(handler); _notifHandlers.delete(type);
} }


/** /**
Expand Down

0 comments on commit e51cb34

Please sign in to comment.