Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Commit 54d43d8

Browse files
committed
Exposing reachability status on METDDPClient
1 parent b889b55 commit 54d43d8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Meteor/METDDPClient.h

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef void (^METLogOutCompletionHandler)(NSError *error);
6363
- (void)connect;
6464
- (void)disconnect;
6565

66+
@property (assign, nonatomic, readonly, getter=isNetworkReachable) BOOL networkReachable;
6667
@property (assign, nonatomic, readonly, getter=isConnected) BOOL connected;
6768
@property (assign, nonatomic, readonly) METDDPConnectionStatus connectionStatus;
6869
@property (copy, nonatomic) METAccount *account;
@@ -91,6 +92,8 @@ typedef void (^METLogOutCompletionHandler)(NSError *error);
9192

9293
@optional
9394

95+
- (void)client:(METDDPClient *)client reachabilityStatusDidChange:(BOOL)reachable;
96+
9497
// General info and connection status
9598
- (void)clientWillConnect:(METDDPClient *)client;
9699
- (void)clientWillDisconnect:(METDDPClient *)client;

Meteor/METDDPClient.m

+9
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ - (void)setConnectionStatus:(METDDPConnectionStatus)connectionStatus {
179179
}
180180
}
181181

182+
- (BOOL)isNetworkReachable {
183+
@synchronized(self) {
184+
return _networkReachabilityManager.reachabilityStatus == METNetworkReachabilityStatusReachable;
185+
}
186+
}
187+
182188
- (BOOL)isConnected {
183189
@synchronized(self) {
184190
return _connectionStatus == METDDPConnectionStatusConnected;
@@ -285,6 +291,9 @@ - (void)networkReachabilityManager:(METNetworkReachabilityManager *)reachability
285291
if (reachabilityStatus == METNetworkReachabilityStatusReachable && [UIApplication sharedApplication].applicationState != UIApplicationStateBackground) {
286292
[self connect];
287293
}
294+
if ([_delegate respondsToSelector:@selector(client:reachabilityStatusDidChange:)]) {
295+
[_delegate client:self reachabilityStatusDidChange:reachabilityStatus == METNetworkReachabilityStatusReachable];
296+
}
288297
}
289298

290299
#pragma mark - Message Handling

0 commit comments

Comments
 (0)