Skip to content

Commit 102b170

Browse files
psycotica0Michelle Ellis
authored andcommitted
Don't Reconnect If Network is Not Reachable
This is to cover the case where the app starts in a state of unreachability. We will have already been told that the network was unreachable before we get to the websocket failure, so don't bother retrying in the case where we know the network is unreachable. In the worst case, even if the network is reachable, we know that if the system doesn't know that it is, we will receive the notification when the system realizes it, and that will cause us to reconnect.
1 parent 025e122 commit 102b170

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Source/PusherWebsocketDelegate.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ extension PusherConnection: WebSocketDelegate {
4141
}
4242

4343
if let reconnect = self.options.autoReconnect where reconnect {
44-
let operation = NSBlockOperation {
45-
self.socket.connect()
46-
}
44+
if let reachability = self.reachability where reachability.isReachable() {
45+
let operation = NSBlockOperation {
46+
self.socket.connect()
47+
}
4748

48-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_SEC)), dispatch_get_main_queue()) {
49-
NSOperationQueue.mainQueue().addOperation(operation)
50-
}
49+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(NSEC_PER_SEC)), dispatch_get_main_queue()) {
50+
NSOperationQueue.mainQueue().addOperation(operation)
51+
}
5152

52-
self.reconnectOperation?.cancel()
53-
self.reconnectOperation = operation
53+
self.reconnectOperation?.cancel()
54+
self.reconnectOperation = operation
55+
}
5456
}
5557
}
5658

0 commit comments

Comments
 (0)