[ios][database] Protect against calling off on a non-existent ref

This commit is contained in:
Chris Bianca 2017-10-18 10:29:11 +01:00
parent 31854bae5b
commit 4f51b48430
1 changed files with 5 additions and 3 deletions

View File

@ -246,10 +246,12 @@ RCT_EXPORT_METHOD(on:(NSString *) appName
RCT_EXPORT_METHOD(off:(NSString *) key
eventRegistrationKey:(NSString *) eventRegistrationKey) {
RNFirebaseDatabaseReference *ref = _dbReferences[key];
[ref removeEventListener:eventRegistrationKey];
if (ref) {
[ref removeEventListener:eventRegistrationKey];
if (![ref hasListeners]) {
[_dbReferences removeObjectForKey:key];
if (![ref hasListeners]) {
[_dbReferences removeObjectForKey:key];
}
}
}