afmotion 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/AFMotion.gemspec +19 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/README.md +135 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +6 -0
- data/examples/AppDotNet/.gitignore +13 -0
- data/examples/AppDotNet/Gemfile +4 -0
- data/examples/AppDotNet/Gemfile.lock +48 -0
- data/examples/AppDotNet/Rakefile +10 -0
- data/examples/AppDotNet/app/app_delegate.rb +28 -0
- data/examples/AppDotNet/app/global_timeline_view_controller.rb +84 -0
- data/examples/AppDotNet/app/post.rb +23 -0
- data/examples/AppDotNet/app/post_table_view_cell.rb +44 -0
- data/examples/AppDotNet/app/user.rb +9 -0
- data/examples/AppDotNet/resources/profile-image-placeholder.png +0 -0
- data/examples/AppDotNet/resources/profile-image-placeholder@2x.png +0 -0
- data/examples/AppDotNet/spec/main_spec.rb +9 -0
- data/examples/AppDotNet/vendor/Podfile.lock +11 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/README.md +179 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.plist +56 -0
- data/examples/AppDotNet/vendor/Pods/Pods-prefix.pch +12 -0
- data/examples/AppDotNet/vendor/Pods/Pods-resources.sh +19 -0
- data/examples/AppDotNet/vendor/Pods/Pods.bridgesupport +617 -0
- data/examples/AppDotNet/vendor/Pods/Pods.xcconfig +7 -0
- data/examples/AppDotNet/vendor/Pods/Pods.xcodeproj/project.pbxproj +998 -0
- data/examples/AppDotNet/vendor/Pods/PodsDummy_Pods.m +4 -0
- data/lib/afmotion/http.rb +55 -0
- data/lib/afmotion/http_client.rb +121 -0
- data/lib/afmotion/http_result.rb +25 -0
- data/lib/afmotion/image.rb +10 -0
- data/lib/afmotion/operation.rb +65 -0
- data/lib/afmotion/patch/NSString_NSUrl.rb +11 -0
- data/lib/afmotion/version.rb +5 -0
- data/lib/afmotion.rb +16 -0
- data/pkg/afmotion-0.0.1.gem +0 -0
- data/spec/http_client_spec.rb +104 -0
- data/spec/http_spec.rb +26 -0
- data/spec/operation_spec.rb +41 -0
- data/vendor/Podfile.lock +11 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
- data/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
- data/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/vendor/Pods/AFNetworking/README.md +179 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
- data/vendor/Pods/Pods-Acknowledgements.plist +56 -0
- data/vendor/Pods/Pods-prefix.pch +12 -0
- data/vendor/Pods/Pods-resources.sh +19 -0
- data/vendor/Pods/Pods.bridgesupport +617 -0
- data/vendor/Pods/Pods.xcconfig +7 -0
- data/vendor/Pods/PodsDummy_Pods.m +4 -0
- metadata +218 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
// AFImageRequestOperation.m
|
2
|
+
//
|
3
|
+
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
10
|
+
// furnished to do so, subject to the following conditions:
|
11
|
+
//
|
12
|
+
// The above copyright notice and this permission notice shall be included in
|
13
|
+
// all copies or substantial portions of the Software.
|
14
|
+
//
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
// THE SOFTWARE.
|
22
|
+
|
23
|
+
#import "AFImageRequestOperation.h"
|
24
|
+
|
25
|
+
static dispatch_queue_t af_image_request_operation_processing_queue;
|
26
|
+
static dispatch_queue_t image_request_operation_processing_queue() {
|
27
|
+
if (af_image_request_operation_processing_queue == NULL) {
|
28
|
+
af_image_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.image-request.processing", 0);
|
29
|
+
}
|
30
|
+
|
31
|
+
return af_image_request_operation_processing_queue;
|
32
|
+
}
|
33
|
+
|
34
|
+
@interface AFImageRequestOperation ()
|
35
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
36
|
+
@property (readwrite, nonatomic, strong) UIImage *responseImage;
|
37
|
+
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
38
|
+
@property (readwrite, nonatomic, strong) NSImage *responseImage;
|
39
|
+
#endif
|
40
|
+
@end
|
41
|
+
|
42
|
+
@implementation AFImageRequestOperation
|
43
|
+
@synthesize responseImage = _responseImage;
|
44
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
45
|
+
@synthesize imageScale = _imageScale;
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
49
|
+
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
50
|
+
success:(void (^)(UIImage *image))success
|
51
|
+
{
|
52
|
+
return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, UIImage *image) {
|
53
|
+
if (success) {
|
54
|
+
success(image);
|
55
|
+
}
|
56
|
+
} failure:nil];
|
57
|
+
}
|
58
|
+
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
59
|
+
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
60
|
+
success:(void (^)(NSImage *image))success
|
61
|
+
{
|
62
|
+
return [self imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSImage *image) {
|
63
|
+
if (success) {
|
64
|
+
success(image);
|
65
|
+
}
|
66
|
+
} failure:nil];
|
67
|
+
}
|
68
|
+
#endif
|
69
|
+
|
70
|
+
|
71
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
72
|
+
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
73
|
+
imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
|
74
|
+
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
|
75
|
+
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
|
76
|
+
{
|
77
|
+
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
78
|
+
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
79
|
+
if (success) {
|
80
|
+
UIImage *image = responseObject;
|
81
|
+
if (imageProcessingBlock) {
|
82
|
+
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
83
|
+
UIImage *processedImage = imageProcessingBlock(image);
|
84
|
+
|
85
|
+
dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
|
86
|
+
success(operation.request, operation.response, processedImage);
|
87
|
+
});
|
88
|
+
});
|
89
|
+
} else {
|
90
|
+
success(operation.request, operation.response, image);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
94
|
+
if (failure) {
|
95
|
+
failure(operation.request, operation.response, error);
|
96
|
+
}
|
97
|
+
}];
|
98
|
+
|
99
|
+
|
100
|
+
return requestOperation;
|
101
|
+
}
|
102
|
+
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
103
|
+
+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
104
|
+
imageProcessingBlock:(NSImage *(^)(NSImage *))imageProcessingBlock
|
105
|
+
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success
|
106
|
+
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
|
107
|
+
{
|
108
|
+
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
109
|
+
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
110
|
+
if (success) {
|
111
|
+
NSImage *image = responseObject;
|
112
|
+
if (imageProcessingBlock) {
|
113
|
+
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
114
|
+
NSImage *processedImage = imageProcessingBlock(image);
|
115
|
+
|
116
|
+
dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
|
117
|
+
success(operation.request, operation.response, processedImage);
|
118
|
+
});
|
119
|
+
});
|
120
|
+
} else {
|
121
|
+
success(operation.request, operation.response, image);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
125
|
+
if (failure) {
|
126
|
+
failure(operation.request, operation.response, error);
|
127
|
+
}
|
128
|
+
}];
|
129
|
+
|
130
|
+
return requestOperation;
|
131
|
+
}
|
132
|
+
#endif
|
133
|
+
|
134
|
+
- (id)initWithRequest:(NSURLRequest *)urlRequest {
|
135
|
+
self = [super initWithRequest:urlRequest];
|
136
|
+
if (!self) {
|
137
|
+
return nil;
|
138
|
+
}
|
139
|
+
|
140
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
141
|
+
self.imageScale = [[UIScreen mainScreen] scale];
|
142
|
+
#endif
|
143
|
+
|
144
|
+
return self;
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
149
|
+
- (UIImage *)responseImage {
|
150
|
+
if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
|
151
|
+
UIImage *image = [UIImage imageWithData:self.responseData];
|
152
|
+
|
153
|
+
self.responseImage = [UIImage imageWithCGImage:[image CGImage] scale:self.imageScale orientation:image.imageOrientation];
|
154
|
+
}
|
155
|
+
|
156
|
+
return _responseImage;
|
157
|
+
}
|
158
|
+
|
159
|
+
- (void)setImageScale:(CGFloat)imageScale {
|
160
|
+
#pragma clang diagnostic push
|
161
|
+
#pragma clang diagnostic ignored "-Wfloat-equal"
|
162
|
+
if (imageScale == _imageScale) {
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
#pragma clang diagnostic pop
|
166
|
+
|
167
|
+
_imageScale = imageScale;
|
168
|
+
|
169
|
+
self.responseImage = nil;
|
170
|
+
}
|
171
|
+
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
172
|
+
- (NSImage *)responseImage {
|
173
|
+
if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) {
|
174
|
+
// Ensure that the image is set to it's correct pixel width and height
|
175
|
+
NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData];
|
176
|
+
self.responseImage = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])];
|
177
|
+
[self.responseImage addRepresentation:bitimage];
|
178
|
+
}
|
179
|
+
|
180
|
+
return _responseImage;
|
181
|
+
}
|
182
|
+
#endif
|
183
|
+
|
184
|
+
#pragma mark - AFHTTPRequestOperation
|
185
|
+
|
186
|
+
+ (NSSet *)acceptableContentTypes {
|
187
|
+
return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil];
|
188
|
+
}
|
189
|
+
|
190
|
+
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
|
191
|
+
static NSSet * _acceptablePathExtension = nil;
|
192
|
+
static dispatch_once_t onceToken;
|
193
|
+
dispatch_once(&onceToken, ^{
|
194
|
+
_acceptablePathExtension = [[NSSet alloc] initWithObjects:@"tif", @"tiff", @"jpg", @"jpeg", @"gif", @"png", @"ico", @"bmp", @"cur", nil];
|
195
|
+
});
|
196
|
+
|
197
|
+
return [_acceptablePathExtension containsObject:[[request URL] pathExtension]] || [super canProcessRequest:request];
|
198
|
+
}
|
199
|
+
|
200
|
+
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
201
|
+
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
202
|
+
{
|
203
|
+
#pragma clang diagnostic push
|
204
|
+
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
205
|
+
self.completionBlock = ^ {
|
206
|
+
if ([self isCancelled]) {
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
|
210
|
+
dispatch_async(image_request_operation_processing_queue(), ^(void) {
|
211
|
+
if (self.error) {
|
212
|
+
if (failure) {
|
213
|
+
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
214
|
+
failure(self, self.error);
|
215
|
+
});
|
216
|
+
}
|
217
|
+
} else {
|
218
|
+
if (success) {
|
219
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
220
|
+
UIImage *image = nil;
|
221
|
+
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
|
222
|
+
NSImage *image = nil;
|
223
|
+
#endif
|
224
|
+
|
225
|
+
image = self.responseImage;
|
226
|
+
|
227
|
+
dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
|
228
|
+
success(self, image);
|
229
|
+
});
|
230
|
+
}
|
231
|
+
}
|
232
|
+
});
|
233
|
+
};
|
234
|
+
#pragma clang diagnostic pop
|
235
|
+
}
|
236
|
+
|
237
|
+
@end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
// AFJSONRequestOperation.h
|
2
|
+
//
|
3
|
+
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
10
|
+
// furnished to do so, subject to the following conditions:
|
11
|
+
//
|
12
|
+
// The above copyright notice and this permission notice shall be included in
|
13
|
+
// all copies or substantial portions of the Software.
|
14
|
+
//
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
// THE SOFTWARE.
|
22
|
+
|
23
|
+
#import <Foundation/Foundation.h>
|
24
|
+
#import "AFHTTPRequestOperation.h"
|
25
|
+
|
26
|
+
/**
|
27
|
+
`AFJSONRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with JSON response data.
|
28
|
+
|
29
|
+
## Acceptable Content Types
|
30
|
+
|
31
|
+
By default, `AFJSONRequestOperation` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types:
|
32
|
+
|
33
|
+
- `application/json`
|
34
|
+
- `text/json`
|
35
|
+
|
36
|
+
@warning JSON parsing will use the built-in `NSJSONSerialization` class.
|
37
|
+
*/
|
38
|
+
@interface AFJSONRequestOperation : AFHTTPRequestOperation
|
39
|
+
|
40
|
+
///----------------------------
|
41
|
+
/// @name Getting Response Data
|
42
|
+
///----------------------------
|
43
|
+
|
44
|
+
/**
|
45
|
+
A JSON object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error.
|
46
|
+
*/
|
47
|
+
@property (readonly, nonatomic, strong) id responseJSON;
|
48
|
+
|
49
|
+
/**
|
50
|
+
Options for reading the response JSON data and creating the Foundation objects. For possible values, see the `NSJSONSerialization` documentation section "NSJSONReadingOptions".
|
51
|
+
*/
|
52
|
+
@property (nonatomic, assign) NSJSONReadingOptions JSONReadingOptions;
|
53
|
+
|
54
|
+
///----------------------------------
|
55
|
+
/// @name Creating Request Operations
|
56
|
+
///----------------------------------
|
57
|
+
|
58
|
+
/**
|
59
|
+
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks.
|
60
|
+
|
61
|
+
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
62
|
+
@param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the JSON object created from the response data of request.
|
63
|
+
@param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as JSON. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred.
|
64
|
+
|
65
|
+
@return A new JSON request operation
|
66
|
+
*/
|
67
|
+
+ (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
68
|
+
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
69
|
+
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure;
|
70
|
+
|
71
|
+
@end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
// AFJSONRequestOperation.m
|
2
|
+
//
|
3
|
+
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
10
|
+
// furnished to do so, subject to the following conditions:
|
11
|
+
//
|
12
|
+
// The above copyright notice and this permission notice shall be included in
|
13
|
+
// all copies or substantial portions of the Software.
|
14
|
+
//
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
// THE SOFTWARE.
|
22
|
+
|
23
|
+
#import "AFJSONRequestOperation.h"
|
24
|
+
|
25
|
+
static dispatch_queue_t af_json_request_operation_processing_queue;
|
26
|
+
static dispatch_queue_t json_request_operation_processing_queue() {
|
27
|
+
if (af_json_request_operation_processing_queue == NULL) {
|
28
|
+
af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.json-request.processing", 0);
|
29
|
+
}
|
30
|
+
|
31
|
+
return af_json_request_operation_processing_queue;
|
32
|
+
}
|
33
|
+
|
34
|
+
@interface AFJSONRequestOperation ()
|
35
|
+
@property (readwrite, nonatomic, strong) id responseJSON;
|
36
|
+
@property (readwrite, nonatomic, strong) NSError *JSONError;
|
37
|
+
@end
|
38
|
+
|
39
|
+
@implementation AFJSONRequestOperation
|
40
|
+
@synthesize responseJSON = _responseJSON;
|
41
|
+
@synthesize JSONReadingOptions = _JSONReadingOptions;
|
42
|
+
@synthesize JSONError = _JSONError;
|
43
|
+
|
44
|
+
+ (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
45
|
+
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
|
46
|
+
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure
|
47
|
+
{
|
48
|
+
AFJSONRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
|
49
|
+
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
50
|
+
if (success) {
|
51
|
+
success(operation.request, operation.response, responseObject);
|
52
|
+
}
|
53
|
+
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
54
|
+
if (failure) {
|
55
|
+
failure(operation.request, operation.response, error, [(AFJSONRequestOperation *)operation responseJSON]);
|
56
|
+
}
|
57
|
+
}];
|
58
|
+
|
59
|
+
return requestOperation;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
- (id)responseJSON {
|
64
|
+
if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) {
|
65
|
+
NSError *error = nil;
|
66
|
+
|
67
|
+
if ([self.responseData length] == 0) {
|
68
|
+
self.responseJSON = nil;
|
69
|
+
} else {
|
70
|
+
self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:self.JSONReadingOptions error:&error];
|
71
|
+
}
|
72
|
+
|
73
|
+
self.JSONError = error;
|
74
|
+
}
|
75
|
+
|
76
|
+
return _responseJSON;
|
77
|
+
}
|
78
|
+
|
79
|
+
- (NSError *)error {
|
80
|
+
if (_JSONError) {
|
81
|
+
return _JSONError;
|
82
|
+
} else {
|
83
|
+
return [super error];
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
#pragma mark - AFHTTPRequestOperation
|
88
|
+
|
89
|
+
+ (NSSet *)acceptableContentTypes {
|
90
|
+
return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];
|
91
|
+
}
|
92
|
+
|
93
|
+
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
|
94
|
+
return [[[request URL] pathExtension] isEqualToString:@"json"] || [super canProcessRequest:request];
|
95
|
+
}
|
96
|
+
|
97
|
+
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
98
|
+
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
99
|
+
{
|
100
|
+
#pragma clang diagnostic push
|
101
|
+
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
102
|
+
self.completionBlock = ^ {
|
103
|
+
if ([self isCancelled]) {
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
|
107
|
+
if (self.error) {
|
108
|
+
if (failure) {
|
109
|
+
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
110
|
+
failure(self, self.error);
|
111
|
+
});
|
112
|
+
}
|
113
|
+
} else {
|
114
|
+
dispatch_async(json_request_operation_processing_queue(), ^{
|
115
|
+
id JSON = self.responseJSON;
|
116
|
+
|
117
|
+
if (self.JSONError) {
|
118
|
+
if (failure) {
|
119
|
+
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
120
|
+
failure(self, self.error);
|
121
|
+
});
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
if (success) {
|
125
|
+
dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
|
126
|
+
success(self, JSON);
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
});
|
131
|
+
}
|
132
|
+
};
|
133
|
+
#pragma clang diagnostic pop
|
134
|
+
}
|
135
|
+
|
136
|
+
@end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
// AFNetworkActivityIndicatorManager.h
|
2
|
+
//
|
3
|
+
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
10
|
+
// furnished to do so, subject to the following conditions:
|
11
|
+
//
|
12
|
+
// The above copyright notice and this permission notice shall be included in
|
13
|
+
// all copies or substantial portions of the Software.
|
14
|
+
//
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
// THE SOFTWARE.
|
22
|
+
|
23
|
+
#import <Foundation/Foundation.h>
|
24
|
+
|
25
|
+
#import <Availability.h>
|
26
|
+
|
27
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
28
|
+
#import <UIKit/UIKit.h>
|
29
|
+
|
30
|
+
/**
|
31
|
+
`AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero.
|
32
|
+
|
33
|
+
You should enable the shared instance of `AFNetworkActivityIndicatorManager` when your application finishes launching. In `AppDelegate application:didFinishLaunchingWithOptions:` you can do so with the following code:
|
34
|
+
|
35
|
+
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
|
36
|
+
|
37
|
+
By setting `isNetworkActivityIndicatorVisible` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself.
|
38
|
+
|
39
|
+
See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information:
|
40
|
+
http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44
|
41
|
+
*/
|
42
|
+
@interface AFNetworkActivityIndicatorManager : NSObject
|
43
|
+
|
44
|
+
/**
|
45
|
+
A Boolean value indicating whether the manager is enabled.
|
46
|
+
|
47
|
+
@discussion If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO.
|
48
|
+
*/
|
49
|
+
@property (nonatomic, assign, getter = isEnabled) BOOL enabled;
|
50
|
+
|
51
|
+
/**
|
52
|
+
A Boolean value indicating whether the network activity indicator is currently displayed in the status bar.
|
53
|
+
*/
|
54
|
+
@property (readonly, nonatomic, assign) BOOL isNetworkActivityIndicatorVisible;
|
55
|
+
|
56
|
+
/**
|
57
|
+
Returns the shared network activity indicator manager object for the system.
|
58
|
+
|
59
|
+
@return The systemwide network activity indicator manager.
|
60
|
+
*/
|
61
|
+
+ (AFNetworkActivityIndicatorManager *)sharedManager;
|
62
|
+
|
63
|
+
/**
|
64
|
+
Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator.
|
65
|
+
*/
|
66
|
+
- (void)incrementActivityCount;
|
67
|
+
|
68
|
+
/**
|
69
|
+
Decrements the number of active network requests. If this number becomes zero before decrementing, this will stop animating the status bar network activity indicator.
|
70
|
+
*/
|
71
|
+
- (void)decrementActivityCount;
|
72
|
+
|
73
|
+
@end
|
74
|
+
|
75
|
+
#endif
|
@@ -0,0 +1,131 @@
|
|
1
|
+
// AFNetworkActivityIndicatorManager.m
|
2
|
+
//
|
3
|
+
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
|
4
|
+
//
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
10
|
+
// furnished to do so, subject to the following conditions:
|
11
|
+
//
|
12
|
+
// The above copyright notice and this permission notice shall be included in
|
13
|
+
// all copies or substantial portions of the Software.
|
14
|
+
//
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
// THE SOFTWARE.
|
22
|
+
|
23
|
+
#import "AFNetworkActivityIndicatorManager.h"
|
24
|
+
|
25
|
+
#import "AFHTTPRequestOperation.h"
|
26
|
+
|
27
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
28
|
+
static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17;
|
29
|
+
|
30
|
+
@interface AFNetworkActivityIndicatorManager ()
|
31
|
+
@property (readwrite, assign) NSInteger activityCount;
|
32
|
+
@property (readwrite, nonatomic, strong) NSTimer *activityIndicatorVisibilityTimer;
|
33
|
+
@property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
|
34
|
+
|
35
|
+
- (void)updateNetworkActivityIndicatorVisibility;
|
36
|
+
- (void)updateNetworkActivityIndicatorVisibilityDelayed;
|
37
|
+
@end
|
38
|
+
|
39
|
+
@implementation AFNetworkActivityIndicatorManager
|
40
|
+
@synthesize activityCount = _activityCount;
|
41
|
+
@synthesize activityIndicatorVisibilityTimer = _activityIndicatorVisibilityTimer;
|
42
|
+
@synthesize enabled = _enabled;
|
43
|
+
@dynamic networkActivityIndicatorVisible;
|
44
|
+
|
45
|
+
+ (AFNetworkActivityIndicatorManager *)sharedManager {
|
46
|
+
static AFNetworkActivityIndicatorManager *_sharedManager = nil;
|
47
|
+
static dispatch_once_t oncePredicate;
|
48
|
+
dispatch_once(&oncePredicate, ^{
|
49
|
+
_sharedManager = [[self alloc] init];
|
50
|
+
});
|
51
|
+
|
52
|
+
return _sharedManager;
|
53
|
+
}
|
54
|
+
|
55
|
+
+ (NSSet *)keyPathsForValuesAffectingIsNetworkActivityIndicatorVisible {
|
56
|
+
return [NSSet setWithObject:@"activityCount"];
|
57
|
+
}
|
58
|
+
|
59
|
+
- (id)init {
|
60
|
+
self = [super init];
|
61
|
+
if (!self) {
|
62
|
+
return nil;
|
63
|
+
}
|
64
|
+
|
65
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incrementActivityCount) name:AFNetworkingOperationDidStartNotification object:nil];
|
66
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(decrementActivityCount) name:AFNetworkingOperationDidFinishNotification object:nil];
|
67
|
+
|
68
|
+
return self;
|
69
|
+
}
|
70
|
+
|
71
|
+
- (void)dealloc {
|
72
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
73
|
+
|
74
|
+
[_activityIndicatorVisibilityTimer invalidate];
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
- (void)updateNetworkActivityIndicatorVisibilityDelayed {
|
79
|
+
if (self.enabled) {
|
80
|
+
// Delay hiding of activity indicator for a short interval, to avoid flickering
|
81
|
+
if (![self isNetworkActivityIndicatorVisible]) {
|
82
|
+
[self.activityIndicatorVisibilityTimer invalidate];
|
83
|
+
self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO];
|
84
|
+
[[NSRunLoop mainRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes];
|
85
|
+
} else {
|
86
|
+
[self performSelectorOnMainThread:@selector(updateNetworkActivityIndicatorVisibility) withObject:nil waitUntilDone:NO modes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
- (BOOL)isNetworkActivityIndicatorVisible {
|
92
|
+
return _activityCount > 0;
|
93
|
+
}
|
94
|
+
|
95
|
+
- (void)updateNetworkActivityIndicatorVisibility {
|
96
|
+
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]];
|
97
|
+
}
|
98
|
+
|
99
|
+
// Not exposed, but used if activityCount is set via KVC.
|
100
|
+
- (NSInteger)activityCount {
|
101
|
+
return _activityCount;
|
102
|
+
}
|
103
|
+
|
104
|
+
- (void)setActivityCount:(NSInteger)activityCount {
|
105
|
+
@synchronized(self) {
|
106
|
+
_activityCount = activityCount;
|
107
|
+
}
|
108
|
+
[self updateNetworkActivityIndicatorVisibilityDelayed];
|
109
|
+
}
|
110
|
+
|
111
|
+
- (void)incrementActivityCount {
|
112
|
+
[self willChangeValueForKey:@"activityCount"];
|
113
|
+
@synchronized(self) {
|
114
|
+
_activityCount++;
|
115
|
+
}
|
116
|
+
[self didChangeValueForKey:@"activityCount"];
|
117
|
+
[self updateNetworkActivityIndicatorVisibilityDelayed];
|
118
|
+
}
|
119
|
+
|
120
|
+
- (void)decrementActivityCount {
|
121
|
+
[self willChangeValueForKey:@"activityCount"];
|
122
|
+
@synchronized(self) {
|
123
|
+
_activityCount = MAX(_activityCount - 1, 0);
|
124
|
+
}
|
125
|
+
[self didChangeValueForKey:@"activityCount"];
|
126
|
+
[self updateNetworkActivityIndicatorVisibilityDelayed];
|
127
|
+
}
|
128
|
+
|
129
|
+
@end
|
130
|
+
|
131
|
+
#endif
|