From e0d76d218d5e002acc00f1972996b1b846240acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 19 Aug 2021 11:43:49 +0800 Subject: [PATCH] iOS: remove sync in dealloc & add some weak-strong-dance --- .../Classes/Plugin/DoricNotificationPlugin.m | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m index ef2fce02..c16ada6f 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricNotificationPlugin.m @@ -87,24 +87,17 @@ - (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise { } - (void)unsubscribe:(NSString *)subscribeId withPromise:(DoricPromise *)promise { - __block id observer = nil; - dispatch_sync(self.syncQuene, ^{ - observer = [self.observers objectForKey:subscribeId]; - }); - if (observer) { + dispatch_barrier_async(self.syncQuene, ^{ + id observer = [self.observers objectForKey:subscribeId]; [[NSNotificationCenter defaultCenter] removeObserver:observer]; - dispatch_barrier_async(self.syncQuene, ^{ - [self.observers removeObjectForKey:subscribeId]; - }); - } - [promise resolve:nil]; + [self.observers removeObjectForKey:subscribeId]; + + [promise resolve:nil]; + }); } - (void)dealloc { - __block NSArray *values; - dispatch_sync(self.syncQuene, ^{ - values = [self.observers allValues]; - }); + NSArray *values = [self.observers allValues]; [values enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { [[NSNotificationCenter defaultCenter] removeObserver:obj]; }];