Permalink
Browse files

Allowing a custom URL request in case more control is needed over the

request than just setting the URL. Supersedes the URL property.
  • Loading branch information...
1 parent b578251 commit 10783e1537d1433066f8dcb26b2df99e7c9f3fda @thillerson thillerson committed Sep 9, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −0 Core/Source/DTLazyImageView.h
  2. +8 −2 Core/Source/DTLazyImageView.m
@@ -18,6 +18,7 @@
@interface DTLazyImageView : UIImageView
@property (nonatomic, strong) NSURL *url;
+@property (nonatomic, strong) NSMutableURLRequest *urlRequest;
@property (nonatomic, assign) BOOL shouldShowProgressiveDownload;
@property (nonatomic, assign) id<DTLazyImageViewDelegate> delegate; // subtle simulator bug - use assign not __unsafe_unretained
@@ -52,9 +52,14 @@ - (void)loadImageAtURL:(NSURL *)url
@autoreleasepool
{
- NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
+ if (_urlRequest == nil) {
+ _urlRequest = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10.0];
+ } else {
+ [_urlRequest setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
+ [_urlRequest setTimeoutInterval:10.0];
+ }
- _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
+ _connection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self startImmediately:NO];
[_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[_connection start];
@@ -277,5 +282,6 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
@synthesize url = _url;
@synthesize shouldShowProgressiveDownload;
+@synthesize urlRequest = _urlRequest;
@end

0 comments on commit 10783e1

Please sign in to comment.