Created
November 12, 2013 01:55
-
-
Save cremaschi/7424077 to your computer and use it in GitHub Desktop.
A category on the NSError to check if it's a "No Internet Connection" error.
For example you can use it on a network request completion to display a proper message.
This file contains 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
// | |
// NSError+NoConnection.h | |
// | |
// Created by Maurizio Cremaschi on 01/11/2013. | |
// Copyright (c) 2013 Myfleek Ltd. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSError (NoConnection) | |
- (BOOL)isNoInternetConnectionError; | |
@end |
This file contains 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
// | |
// NSError+NoConnection.m | |
// | |
// Created by Maurizio Cremaschi on 01/11/2013. | |
// Copyright (c) 2013 Myfleek Ltd. All rights reserved. | |
// | |
#import "NSError+NoConnection.h" | |
@implementation NSError (NoConnection) | |
- (BOOL)isNoInternetConnectionError | |
{ | |
return ([self.domain isEqualToString:NSURLErrorDomain] && (self.code == NSURLErrorNotConnectedToInternet)); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I Think (||) instead of (&&) will do the work cause mostly not both errors is happening together in the same time :)