PushNotificationIOS: Use PushNotificationEventName as the key to store 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 https://github.com/facebook/react-native/pull/10776

Differential Revision: D4168722

Pulled By: hramos

fbshipit-source-id: d68581428d2acde314f7b5333feafe1ec7807159
This commit is contained in:
ianlin 2016-11-14 12:44:16 -08:00 коммит произвёл Facebook Github Bot
Родитель 015a497cf1
Коммит e51cb349ce
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

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