Break retain cycle and fix bug

pull/8441/head
Muxi Yan 8 years ago
parent b93053f868
commit 5655130171
  1. 2
      src/objective-c/GRPCClient/GRPCCall.m
  2. 16
      src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m

@ -382,7 +382,7 @@ static NSMutableDictionary *callFlags;
[NSException raise:NSInvalidArgumentException format:@"host of %@ is nil", _host]; [NSException raise:NSInvalidArgumentException format:@"host of %@ is nil", _host];
} }
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
_connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:host]; _connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:host];
void (^handler)() = ^{ void (^handler)() = ^{
typeof(self) strongSelf = weakSelf; typeof(self) strongSelf = weakSelf;
if (strongSelf) { if (strongSelf) {

@ -153,14 +153,18 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
- (void)handleLossWithHandler:(void (^)())handler - (void)handleLossWithHandler:(void (^)())handler
wifiStatusChangeHandler:(nonnull void (^)())wifiStatusChangeHandler { wifiStatusChangeHandler:(nonnull void (^)())wifiStatusChangeHandler {
__weak typeof(self) weakSelf = self;
[self startListeningWithHandler:^(GRPCReachabilityFlags *flags) { [self startListeningWithHandler:^(GRPCReachabilityFlags *flags) {
if (!flags.reachable) { typeof(self) strongSelf = weakSelf;
handler(); if (strongSelf) {
} else if (!_previousReachabilityFlags || if (!flags.reachable) {
(flags.isWWAN ^ _previousReachabilityFlags.isWWAN)) { handler();
wifiStatusChangeHandler(); } else if (strongSelf->_previousReachabilityFlags &&
(flags.isWWAN ^ strongSelf->_previousReachabilityFlags.isWWAN)) {
wifiStatusChangeHandler();
}
strongSelf->_previousReachabilityFlags = flags;
} }
_previousReachabilityFlags = flags;
}]; }];
} }

Loading…
Cancel
Save