iOS: remove sync in dealloc & add some weak-strong-dance

This commit is contained in:
王劲鹏 2021-08-19 11:43:49 +08:00 committed by osborn
parent 67915e6db0
commit e0d76d218d

View File

@ -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) {
[[NSNotificationCenter defaultCenter] removeObserver:observer];
dispatch_barrier_async(self.syncQuene, ^{
id observer = [self.observers objectForKey:subscribeId];
[[NSNotificationCenter defaultCenter] removeObserver:observer];
[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];
}];