Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow DTLazyImage URL request customization #216

Merged
merged 2 commits into from

2 participants

@thillerson

In an application we're working on we often load protected content, so we need to modify the URL request of image requests from DTLazyImage. This modification will allow the user to customize the URL request used to load the image.

@Cocoanetics Cocoanetics merged commit dec8212 into Cocoanetics:master
@Cocoanetics
Owner

Interesting work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 9, 2012
  1. @thillerson

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

    thillerson authored
    request than just setting the URL. Supersedes the URL property.
  2. @thillerson
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 3 deletions.
  1. +1 −0  Core/Source/DTLazyImageView.h
  2. +14 −3 Core/Source/DTLazyImageView.m
View
1  Core/Source/DTLazyImageView.h
@@ -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
View
17 Core/Source/DTLazyImageView.m
@@ -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];
@@ -67,7 +72,7 @@ - (void)didMoveToSuperview
{
[super didMoveToSuperview];
- if (!self.image && _url && !_connection && self.superview)
+ if (!self.image && (_url || _urlRequest) && !_connection && self.superview)
{
UIImage *image = [_imageCache objectForKey:_url];
@@ -277,5 +282,11 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
@synthesize url = _url;
@synthesize shouldShowProgressiveDownload;
+@synthesize urlRequest = _urlRequest;
+
+- (void) setUrlRequest:(NSMutableURLRequest *)request {
+ _urlRequest = request;
+ self.url = [_urlRequest URL];
+}
@end
Something went wrong with that request. Please try again.