From fbaab54b407f74fc12c39e4101b363d4689ca100 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 24 Sep 2020 07:31:15 -0400 Subject: [PATCH] fix(ios): iterate listeners to avoid mutated while being enumerated (#3572) --- ios/Capacitor/Capacitor/CAPPlugin.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPPlugin.m b/ios/Capacitor/Capacitor/CAPPlugin.m index f0fe9e14e..ddfa79bf1 100644 --- a/ios/Capacitor/Capacitor/CAPPlugin.m +++ b/ios/Capacitor/Capacitor/CAPPlugin.m @@ -99,10 +99,13 @@ - (void)notifyListeners:(NSString *)eventName data:(NSDictionary } return; } - - for(CAPPluginCall *call in listenersForEvent) { - CAPPluginCallResult *result = [[CAPPluginCallResult alloc] init:data]; - call.successHandler(result, call); + + for (int i=0; i < listenersForEvent.count; i++) { + CAPPluginCall *call = listenersForEvent[i]; + if (call != nil) { + CAPPluginCallResult *result = [[CAPPluginCallResult alloc] init:data]; + call.successHandler(result, call); + } } }