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

Commit b889b55

Browse files
committed
Only start network monitoring service after the first call to connect in METDDPClient
1 parent 8b394db commit b889b55

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Meteor/METDDPClient.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ - (instancetype)initWithConnection:(METDDPConnection *)connection account:(METAc
107107
_networkReachabilityManager = [[METNetworkReachabilityManager alloc] initWithHostName:connection.serverURL.host];
108108
_networkReachabilityManager.delegate = self;
109109
_networkReachabilityManager.delegateQueue = _queue;
110-
[_networkReachabilityManager startMonitoring];
111110

112111
_keepAliveBackgroundTask = UIBackgroundTaskInvalid;
113112

@@ -188,6 +187,7 @@ - (BOOL)isConnected {
188187

189188
- (void)connect {
190189
@synchronized(self) {
190+
[_networkReachabilityManager startMonitoring];
191191
if (_connectionStatus == METDDPConnectionStatusOffline || _connectionStatus == METDDPConnectionStatusWaiting) {
192192
if ([_delegate respondsToSelector:@selector(clientWillConnect:)]) {
193193
[_delegate clientWillConnect:self];

Meteor/METNetworkReachabilityManager.m

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static void METNetworkReachabilityCallback(SCNetworkReachabilityRef target, SCNe
3535

3636
@implementation METNetworkReachabilityManager {
3737
SCNetworkReachabilityRef _reachabilityRef;
38+
BOOL _started;
3839
}
3940

4041
#pragma mark - Lifecycle
@@ -61,14 +62,15 @@ - (void)dealloc {
6162

6263
- (BOOL)startMonitoring {
6364
NSAssert(_delegateQueue != nil, @"Delegate queue should be set before calling startMonitoring");
64-
65+
if (_started) {
66+
return YES;
67+
}
6568
SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
6669

6770
if (SCNetworkReachabilitySetCallback(_reachabilityRef, METNetworkReachabilityCallback, &context)) {
68-
return SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _delegateQueue);
71+
_started = SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _delegateQueue);
6972
}
70-
71-
return NO;
73+
return _started;
7274
}
7375

7476
- (void)stopMonitoring {

0 commit comments

Comments
 (0)