-
Notifications
You must be signed in to change notification settings - Fork 0
/
KIFNetworkDisabler.m
47 lines (38 loc) · 1.3 KB
/
KIFNetworkDisabler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "KIFNetworkDisabler.h"
static KIFNetworkDisabler* sharedInstance;
static void releaseInstance()
{
[sharedInstance release];
sharedInstance = nil;
}
@implementation KIFNetworkDisabler
+ (KIFNetworkDisabler *)sharedInstance
{
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
atexit(releaseInstance);
});
return sharedInstance;
}
@synthesize stopNetWork;
- (void)newASImain{
if ([KIFNetworkDisabler sharedInstance].stopNetWork){
NSError* failError = [[NSError alloc] initWithDomain:NetworkRequestErrorDomain code:ASIRequestTimedOutErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request timed out",NSLocalizedDescriptionKey,nil]];
[self failWithError:[failError autorelease]];
}
else{
[self newASImain];
}
}
- (void)newAFoperationDidStart{
if ([KIFNetworkDisabler sharedInstance].stopNetWork){
NSError* failError = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorTimedOut userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"The request timed out",NSLocalizedDescriptionKey,nil]];
[self connection:nil
didFailWithError:[failError autorelease]];
}
else{
[self newAFoperationDidStart];
}
}
@end