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];
}
__weak typeof(self) weakSelf = self;
_connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:host];
_connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:host];
void (^handler)() = ^{
typeof(self) strongSelf = weakSelf;
if (strongSelf) {

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

Loading…
Cancel
Save