Created
September 1, 2012 18:22
-
-
Save alexito4/3582382 to your computer and use it in GitHub Desktop.
AFNetworking - UIImageView+AFNetworking - New method setImageURL + blocks
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
/* | |
If you want to use blocks the only method that works is: | |
setImageWithURLRequest:placeholderImage:success:failure: | |
But you don't want to use URLRequest! | |
*/ | |
// .h | |
- (void)setImageWithURL:(NSURL *)url | |
placeholderImage:(UIImage *)placeholderImage | |
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success | |
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; | |
// .m | |
- (void)setImageWithURL:(NSURL *)url | |
placeholderImage:(UIImage *)placeholderImage | |
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success | |
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure | |
{ | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; | |
[request setHTTPShouldHandleCookies:NO]; | |
[request setHTTPShouldUsePipelining:YES]; | |
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:success failure:failure]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment