afmotion 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/AFMotion.gemspec +1 -1
- data/Gemfile.lock +1 -1
- data/lib/afmotion/version.rb +1 -1
- metadata +3 -67
- data/examples/AppDotNet/.gitignore +0 -13
- data/examples/AppDotNet/Gemfile +0 -4
- data/examples/AppDotNet/Gemfile.lock +0 -48
- data/examples/AppDotNet/Rakefile +0 -10
- data/examples/AppDotNet/app/app_delegate.rb +0 -28
- data/examples/AppDotNet/app/global_timeline_view_controller.rb +0 -84
- data/examples/AppDotNet/app/post.rb +0 -23
- data/examples/AppDotNet/app/post_table_view_cell.rb +0 -44
- data/examples/AppDotNet/app/user.rb +0 -9
- 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 +0 -9
- data/examples/AppDotNet/vendor/Podfile.lock +0 -11
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking.podspec +0 -28
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -574
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1187
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -341
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -108
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -237
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -136
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -131
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -44
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -145
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -652
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -169
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -180
- data/examples/AppDotNet/vendor/Pods/AFNetworking/LICENSE +0 -19
- data/examples/AppDotNet/vendor/Pods/AFNetworking/README.md +0 -179
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -574
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -108
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -44
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -574
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -108
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -44
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -295
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.markdown +0 -26
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.plist +0 -56
- data/examples/AppDotNet/vendor/Pods/Pods-prefix.pch +0 -12
- data/examples/AppDotNet/vendor/Pods/Pods-resources.sh +0 -19
- data/examples/AppDotNet/vendor/Pods/Pods.bridgesupport +0 -617
- data/examples/AppDotNet/vendor/Pods/Pods.xcconfig +0 -7
- data/examples/AppDotNet/vendor/Pods/Pods.xcodeproj/project.pbxproj +0 -998
- data/examples/AppDotNet/vendor/Pods/PodsDummy_Pods.m +0 -4
- data/pkg/afmotion-0.0.1.gem +0 -0
@@ -1,89 +0,0 @@
|
|
1
|
-
// AFXMLRequestOperation.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
|
-
#import <Availability.h>
|
27
|
-
|
28
|
-
/**
|
29
|
-
`AFXMLRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with XML response data.
|
30
|
-
|
31
|
-
## Acceptable Content Types
|
32
|
-
|
33
|
-
By default, `AFXMLRequestOperation` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types:
|
34
|
-
|
35
|
-
- `application/xml`
|
36
|
-
- `text/xml`
|
37
|
-
|
38
|
-
## Use With AFHTTPClient
|
39
|
-
|
40
|
-
When `AFXMLRequestOperation` is registered with `AFHTTPClient`, the response object in the success callback of `HTTPRequestOperationWithRequest:success:failure:` will be an instance of `NSXMLParser`. On platforms that support `NSXMLDocument`, you have the option to ignore the response object, and simply use the `responseXMLDocument` property of the operation argument of the callback.
|
41
|
-
*/
|
42
|
-
@interface AFXMLRequestOperation : AFHTTPRequestOperation
|
43
|
-
|
44
|
-
///----------------------------
|
45
|
-
/// @name Getting Response Data
|
46
|
-
///----------------------------
|
47
|
-
|
48
|
-
/**
|
49
|
-
An `NSXMLParser` object constructed from the response data.
|
50
|
-
*/
|
51
|
-
@property (readonly, nonatomic, strong) NSXMLParser *responseXMLParser;
|
52
|
-
|
53
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
54
|
-
/**
|
55
|
-
An `NSXMLDocument` 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.
|
56
|
-
*/
|
57
|
-
@property (readonly, nonatomic, strong) NSXMLDocument *responseXMLDocument;
|
58
|
-
#endif
|
59
|
-
|
60
|
-
/**
|
61
|
-
Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
|
62
|
-
|
63
|
-
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
64
|
-
@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 XML parser constructed with the response data of request.
|
65
|
-
@param failure A block object to be executed when the operation finishes unsuccessfully. 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 error that occurred.
|
66
|
-
|
67
|
-
@return A new XML request operation
|
68
|
-
*/
|
69
|
-
+ (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
70
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
|
71
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure;
|
72
|
-
|
73
|
-
|
74
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
75
|
-
/**
|
76
|
-
Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
|
77
|
-
|
78
|
-
@param urlRequest The request object to be loaded asynchronously during execution of the operation
|
79
|
-
@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 XML document created from the response data of request.
|
80
|
-
@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 XML. 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.
|
81
|
-
|
82
|
-
@return A new XML request operation
|
83
|
-
*/
|
84
|
-
+ (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
85
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
|
86
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure;
|
87
|
-
#endif
|
88
|
-
|
89
|
-
@end
|
@@ -1,169 +0,0 @@
|
|
1
|
-
// AFXMLRequestOperation.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 "AFXMLRequestOperation.h"
|
24
|
-
|
25
|
-
#include <Availability.h>
|
26
|
-
|
27
|
-
static dispatch_queue_t af_xml_request_operation_processing_queue;
|
28
|
-
static dispatch_queue_t xml_request_operation_processing_queue() {
|
29
|
-
if (af_xml_request_operation_processing_queue == NULL) {
|
30
|
-
af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", 0);
|
31
|
-
}
|
32
|
-
|
33
|
-
return af_xml_request_operation_processing_queue;
|
34
|
-
}
|
35
|
-
|
36
|
-
@interface AFXMLRequestOperation ()
|
37
|
-
@property (readwrite, nonatomic, strong) NSXMLParser *responseXMLParser;
|
38
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
39
|
-
@property (readwrite, nonatomic, strong) NSXMLDocument *responseXMLDocument;
|
40
|
-
#endif
|
41
|
-
@property (readwrite, nonatomic, strong) NSError *XMLError;
|
42
|
-
@end
|
43
|
-
|
44
|
-
@implementation AFXMLRequestOperation
|
45
|
-
@synthesize responseXMLParser = _responseXMLParser;
|
46
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
47
|
-
@synthesize responseXMLDocument = _responseXMLDocument;
|
48
|
-
#endif
|
49
|
-
@synthesize XMLError = _XMLError;
|
50
|
-
|
51
|
-
+ (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
52
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
|
53
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure
|
54
|
-
{
|
55
|
-
AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
|
56
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
57
|
-
if (success) {
|
58
|
-
success(operation.request, operation.response, responseObject);
|
59
|
-
}
|
60
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
61
|
-
if (failure) {
|
62
|
-
failure(operation.request, operation.response, error, [(AFXMLRequestOperation *)operation responseXMLParser]);
|
63
|
-
}
|
64
|
-
}];
|
65
|
-
|
66
|
-
return requestOperation;
|
67
|
-
}
|
68
|
-
|
69
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
70
|
-
+ (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
71
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
|
72
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure
|
73
|
-
{
|
74
|
-
AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
|
75
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, __unused id responseObject) {
|
76
|
-
if (success) {
|
77
|
-
NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
|
78
|
-
success(operation.request, operation.response, XMLDocument);
|
79
|
-
}
|
80
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
81
|
-
if (failure) {
|
82
|
-
NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
|
83
|
-
failure(operation.request, operation.response, error, XMLDocument);
|
84
|
-
}
|
85
|
-
}];
|
86
|
-
|
87
|
-
return requestOperation;
|
88
|
-
}
|
89
|
-
#endif
|
90
|
-
|
91
|
-
|
92
|
-
- (NSXMLParser *)responseXMLParser {
|
93
|
-
if (!_responseXMLParser && [self.responseData length] > 0 && [self isFinished]) {
|
94
|
-
self.responseXMLParser = [[NSXMLParser alloc] initWithData:self.responseData];
|
95
|
-
}
|
96
|
-
|
97
|
-
return _responseXMLParser;
|
98
|
-
}
|
99
|
-
|
100
|
-
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
101
|
-
- (NSXMLDocument *)responseXMLDocument {
|
102
|
-
if (!_responseXMLDocument && [self.responseData length] > 0 && [self isFinished]) {
|
103
|
-
NSError *error = nil;
|
104
|
-
self.responseXMLDocument = [[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error];
|
105
|
-
self.XMLError = error;
|
106
|
-
}
|
107
|
-
|
108
|
-
return _responseXMLDocument;
|
109
|
-
}
|
110
|
-
#endif
|
111
|
-
|
112
|
-
- (NSError *)error {
|
113
|
-
if (_XMLError) {
|
114
|
-
return _XMLError;
|
115
|
-
} else {
|
116
|
-
return [super error];
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
#pragma mark - NSOperation
|
121
|
-
|
122
|
-
- (void)cancel {
|
123
|
-
[super cancel];
|
124
|
-
|
125
|
-
self.responseXMLParser.delegate = nil;
|
126
|
-
}
|
127
|
-
|
128
|
-
#pragma mark - AFHTTPRequestOperation
|
129
|
-
|
130
|
-
+ (NSSet *)acceptableContentTypes {
|
131
|
-
return [NSSet setWithObjects:@"application/xml", @"text/xml", nil];
|
132
|
-
}
|
133
|
-
|
134
|
-
+ (BOOL)canProcessRequest:(NSURLRequest *)request {
|
135
|
-
return [[[request URL] pathExtension] isEqualToString:@"xml"] || [super canProcessRequest:request];
|
136
|
-
}
|
137
|
-
|
138
|
-
- (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
|
139
|
-
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
|
140
|
-
{
|
141
|
-
#pragma clang diagnostic push
|
142
|
-
#pragma clang diagnostic ignored "-Warc-retain-cycles"
|
143
|
-
self.completionBlock = ^ {
|
144
|
-
if ([self isCancelled]) {
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
|
148
|
-
dispatch_async(xml_request_operation_processing_queue(), ^(void) {
|
149
|
-
NSXMLParser *XMLParser = self.responseXMLParser;
|
150
|
-
|
151
|
-
if (self.error) {
|
152
|
-
if (failure) {
|
153
|
-
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
|
154
|
-
failure(self, self.error);
|
155
|
-
});
|
156
|
-
}
|
157
|
-
} else {
|
158
|
-
if (success) {
|
159
|
-
dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
|
160
|
-
success(self, XMLParser);
|
161
|
-
});
|
162
|
-
}
|
163
|
-
}
|
164
|
-
});
|
165
|
-
};
|
166
|
-
#pragma clang diagnostic pop
|
167
|
-
}
|
168
|
-
|
169
|
-
@end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
// UIImageView+AFNetworking.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 "AFImageRequestOperation.h"
|
25
|
-
|
26
|
-
#import <Availability.h>
|
27
|
-
|
28
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
29
|
-
#import <UIKit/UIKit.h>
|
30
|
-
|
31
|
-
/**
|
32
|
-
This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL.
|
33
|
-
*/
|
34
|
-
@interface UIImageView (AFNetworking)
|
35
|
-
|
36
|
-
/**
|
37
|
-
Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL, and sets it the request is finished. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
|
38
|
-
|
39
|
-
@discussion By default, URL requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
|
40
|
-
|
41
|
-
@param url The URL used for the image request.
|
42
|
-
*/
|
43
|
-
- (void)setImageWithURL:(NSURL *)url;
|
44
|
-
|
45
|
-
/**
|
46
|
-
Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
|
47
|
-
|
48
|
-
@param url The URL used for the image request.
|
49
|
-
@param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
|
50
|
-
|
51
|
-
@discussion By default, URL requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
|
52
|
-
*/
|
53
|
-
- (void)setImageWithURL:(NSURL *)url
|
54
|
-
placeholderImage:(UIImage *)placeholderImage;
|
55
|
-
|
56
|
-
/**
|
57
|
-
Creates and enqueues an image request operation, which asynchronously downloads the image with the specified URL request object. Any previous image request for the receiver will be cancelled. If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
|
58
|
-
|
59
|
-
@param urlRequest The URL request used for the image request.
|
60
|
-
@param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
|
61
|
-
@param success A block to be executed when the image request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the request and response parameters will be `nil`.
|
62
|
-
@param failure A block object to be executed when the image request operation finishes unsuccessfully, or that 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 error object describing the network or parsing error that occurred.
|
63
|
-
|
64
|
-
@discussion If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is executed.
|
65
|
-
*/
|
66
|
-
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
|
67
|
-
placeholderImage:(UIImage *)placeholderImage
|
68
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
|
69
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
|
70
|
-
|
71
|
-
/**
|
72
|
-
Cancels any executing image request operation for the receiver, if one exists.
|
73
|
-
*/
|
74
|
-
- (void)cancelImageRequestOperation;
|
75
|
-
|
76
|
-
@end
|
77
|
-
|
78
|
-
#endif
|
@@ -1,180 +0,0 @@
|
|
1
|
-
// UIImageView+AFNetworking.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 <Foundation/Foundation.h>
|
24
|
-
#import <objc/runtime.h>
|
25
|
-
|
26
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
27
|
-
#import "UIImageView+AFNetworking.h"
|
28
|
-
|
29
|
-
@interface AFImageCache : NSCache
|
30
|
-
- (UIImage *)cachedImageForRequest:(NSURLRequest *)request;
|
31
|
-
- (void)cacheImage:(UIImage *)image
|
32
|
-
forRequest:(NSURLRequest *)request;
|
33
|
-
@end
|
34
|
-
|
35
|
-
#pragma mark -
|
36
|
-
|
37
|
-
static char kAFImageRequestOperationObjectKey;
|
38
|
-
|
39
|
-
@interface UIImageView (_AFNetworking)
|
40
|
-
@property (readwrite, nonatomic, strong, setter = af_setImageRequestOperation:) AFImageRequestOperation *af_imageRequestOperation;
|
41
|
-
@end
|
42
|
-
|
43
|
-
@implementation UIImageView (_AFNetworking)
|
44
|
-
@dynamic af_imageRequestOperation;
|
45
|
-
@end
|
46
|
-
|
47
|
-
#pragma mark -
|
48
|
-
|
49
|
-
@implementation UIImageView (AFNetworking)
|
50
|
-
|
51
|
-
- (AFHTTPRequestOperation *)af_imageRequestOperation {
|
52
|
-
return (AFHTTPRequestOperation *)objc_getAssociatedObject(self, &kAFImageRequestOperationObjectKey);
|
53
|
-
}
|
54
|
-
|
55
|
-
- (void)af_setImageRequestOperation:(AFImageRequestOperation *)imageRequestOperation {
|
56
|
-
objc_setAssociatedObject(self, &kAFImageRequestOperationObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
57
|
-
}
|
58
|
-
|
59
|
-
+ (NSOperationQueue *)af_sharedImageRequestOperationQueue {
|
60
|
-
static NSOperationQueue *_af_imageRequestOperationQueue = nil;
|
61
|
-
static dispatch_once_t onceToken;
|
62
|
-
dispatch_once(&onceToken, ^{
|
63
|
-
_af_imageRequestOperationQueue = [[NSOperationQueue alloc] init];
|
64
|
-
[_af_imageRequestOperationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
|
65
|
-
});
|
66
|
-
|
67
|
-
return _af_imageRequestOperationQueue;
|
68
|
-
}
|
69
|
-
|
70
|
-
+ (AFImageCache *)af_sharedImageCache {
|
71
|
-
static AFImageCache *_af_imageCache = nil;
|
72
|
-
static dispatch_once_t oncePredicate;
|
73
|
-
dispatch_once(&oncePredicate, ^{
|
74
|
-
_af_imageCache = [[AFImageCache alloc] init];
|
75
|
-
});
|
76
|
-
|
77
|
-
return _af_imageCache;
|
78
|
-
}
|
79
|
-
|
80
|
-
#pragma mark -
|
81
|
-
|
82
|
-
- (void)setImageWithURL:(NSURL *)url {
|
83
|
-
[self setImageWithURL:url placeholderImage:nil];
|
84
|
-
}
|
85
|
-
|
86
|
-
- (void)setImageWithURL:(NSURL *)url
|
87
|
-
placeholderImage:(UIImage *)placeholderImage
|
88
|
-
{
|
89
|
-
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
90
|
-
[request setHTTPShouldHandleCookies:NO];
|
91
|
-
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
|
92
|
-
|
93
|
-
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
|
94
|
-
}
|
95
|
-
|
96
|
-
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
|
97
|
-
placeholderImage:(UIImage *)placeholderImage
|
98
|
-
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
|
99
|
-
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
|
100
|
-
{
|
101
|
-
[self cancelImageRequestOperation];
|
102
|
-
|
103
|
-
UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
|
104
|
-
if (cachedImage) {
|
105
|
-
self.image = cachedImage;
|
106
|
-
self.af_imageRequestOperation = nil;
|
107
|
-
|
108
|
-
if (success) {
|
109
|
-
success(nil, nil, cachedImage);
|
110
|
-
}
|
111
|
-
} else {
|
112
|
-
self.image = placeholderImage;
|
113
|
-
|
114
|
-
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
115
|
-
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
116
|
-
if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
|
117
|
-
if (success) {
|
118
|
-
success(operation.request, operation.response, responseObject);
|
119
|
-
} else {
|
120
|
-
self.image = responseObject;
|
121
|
-
}
|
122
|
-
|
123
|
-
self.af_imageRequestOperation = nil;
|
124
|
-
}
|
125
|
-
|
126
|
-
[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
|
127
|
-
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
128
|
-
if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
|
129
|
-
if (failure) {
|
130
|
-
failure(operation.request, operation.response, error);
|
131
|
-
}
|
132
|
-
|
133
|
-
self.af_imageRequestOperation = nil;
|
134
|
-
}
|
135
|
-
}];
|
136
|
-
|
137
|
-
self.af_imageRequestOperation = requestOperation;
|
138
|
-
|
139
|
-
[[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];
|
140
|
-
}
|
141
|
-
}
|
142
|
-
|
143
|
-
- (void)cancelImageRequestOperation {
|
144
|
-
[self.af_imageRequestOperation cancel];
|
145
|
-
self.af_imageRequestOperation = nil;
|
146
|
-
}
|
147
|
-
|
148
|
-
@end
|
149
|
-
|
150
|
-
#pragma mark -
|
151
|
-
|
152
|
-
static inline NSString * AFImageCacheKeyFromURLRequest(NSURLRequest *request) {
|
153
|
-
return [[request URL] absoluteString];
|
154
|
-
}
|
155
|
-
|
156
|
-
@implementation AFImageCache
|
157
|
-
|
158
|
-
- (UIImage *)cachedImageForRequest:(NSURLRequest *)request {
|
159
|
-
switch ([request cachePolicy]) {
|
160
|
-
case NSURLRequestReloadIgnoringCacheData:
|
161
|
-
case NSURLRequestReloadIgnoringLocalAndRemoteCacheData:
|
162
|
-
return nil;
|
163
|
-
default:
|
164
|
-
break;
|
165
|
-
}
|
166
|
-
|
167
|
-
return [self objectForKey:AFImageCacheKeyFromURLRequest(request)];
|
168
|
-
}
|
169
|
-
|
170
|
-
- (void)cacheImage:(UIImage *)image
|
171
|
-
forRequest:(NSURLRequest *)request
|
172
|
-
{
|
173
|
-
if (image && request) {
|
174
|
-
[self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)];
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
@end
|
179
|
-
|
180
|
-
#endif
|