diff options
author | Muxi Yan <mxyan@google.com> | 2016-10-30 21:10:57 -0700 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2016-10-30 21:10:57 -0700 |
commit | 411969a67cc34c6ce822c7a76f476698fc4eb353 (patch) | |
tree | 1a675a6a78fbcf7c21d519536dad9f223086335a /src/objective-c/GRPCClient | |
parent | aea7d313943da4bcf7f6acb0957975645f951644 (diff) |
Mark connectivity closures as nullable and check null when invoking them
Diffstat (limited to 'src/objective-c/GRPCClient')
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h | 4 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m | 9 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h index be58138c78..e341b6ef6c 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h @@ -72,6 +72,6 @@ * Only one handler is active at a time, so if this method is called again before the previous * handler has been called, it might never be called at all (or yes, if it has already been queued). */ -- (void)handleLossWithHandler:(void (^)())lossHandler - wifiStatusChangeHandler:(void (^)())wifiStatusChangeHandler; +- (void)handleLossWithHandler:(nullable void (^)())lossHandler + wifiStatusChangeHandler:(nullable void (^)())wifiStatusChangeHandler; @end diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m index c6f6b39b61..40afca2d3d 100644 --- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m +++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m @@ -151,15 +151,16 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, return returnValue; } -- (void)handleLossWithHandler:(void (^)())lossHandler - wifiStatusChangeHandler:(void (^)())wifiStatusChangeHandler { +- (void)handleLossWithHandler:(nullable void (^)())lossHandler + wifiStatusChangeHandler:(nullable void (^)())wifiStatusChangeHandler { __weak typeof(self) weakSelf = self; [self startListeningWithHandler:^(GRPCReachabilityFlags *flags) { typeof(self) strongSelf = weakSelf; if (strongSelf) { - if (!flags.reachable) { + if (lossHandler && !flags.reachable) { lossHandler(); - } else if (strongSelf->_previousReachabilityFlags && + } else if (wifiStatusChangeHandler && + strongSelf->_previousReachabilityFlags && (flags.isWWAN ^ strongSelf->_previousReachabilityFlags.isWWAN)) { wifiStatusChangeHandler(); |