Last active
December 31, 2015 22:29
-
-
Save danielctull/8053604 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)checkConnectionWithError:(NSError *)error { | |
| CWDURLSessionManagerState state = CWDURLSessionManagerStateConnected; | |
| NSNumber *errorCode = @(error.code); | |
| if ([[self noInternetErrorCodes] containsObject:errorCode]) | |
| state = CWDURLSessionManagerStateNotConnected; | |
| if (self.state == state) return; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| self.state = state; | |
| }); | |
| } | |
| - (NSArray *)noInternetErrorCodes { | |
| static NSArray *noInternetErrorCodes; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| noInternetErrorCodes = @[ | |
| @(NSURLErrorCannotFindHost), | |
| @(NSURLErrorCannotConnectToHost), | |
| @(NSURLErrorNetworkConnectionLost), | |
| @(NSURLErrorDNSLookupFailed), | |
| @(NSURLErrorHTTPTooManyRedirects), | |
| @(NSURLErrorResourceUnavailable), | |
| @(NSURLErrorNotConnectedToInternet), | |
| @(NSURLErrorRedirectToNonExistentLocation), | |
| @(NSURLErrorInternationalRoamingOff), | |
| @(NSURLErrorCallIsActive), | |
| @(NSURLErrorDataNotAllowed), | |
| @(NSURLErrorSecureConnectionFailed), | |
| @(NSURLErrorCannotLoadFromNetwork) | |
| ]; | |
| }); | |
| return noInternetErrorCodes; | |
| } | |
| - (void)setState:(CWDURLSessionManagerState)state { | |
| if (_state == state) return; | |
| _state = state; | |
| [self.delegate sessionManager:self didChangeState:state]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment