Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AssetManagerTest/AssetManagerTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
B67896F613328E390022CA67 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
ORGANIZATIONNAME = "Zarra Studios LLC";
};
buildConfigurationList = B67896F913328E390022CA67 /* Build configuration list for PBXProject "AssetManagerTest" */;
Expand Down Expand Up @@ -253,6 +254,7 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
INFOPLIST_FILE = Info.plist;
OTHER_LDFLAGS = "-lxml2";
Expand All @@ -268,6 +270,7 @@
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
INFOPLIST_FILE = Info.plist;
OTHER_LDFLAGS = "-lxml2";
Expand Down
23 changes: 21 additions & 2 deletions AssetManagerTest/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@

#define kFeedHREF @"http://api.flickr.com/services/feeds/groups_pool.gne?id=1621520@N24&lang=en-us&format=rss_200"

@interface AppDelegate ()
@property (readwrite, retain) GDataXMLDocument *document;
@end

@implementation AppDelegate

@synthesize assetManager;
@synthesize window;

@synthesize document;

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
Expand All @@ -60,6 +66,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
MCRelease(delegate);

assetManager = [[ZSAssetManager alloc] init];
[root setAssetManager:assetManager];

return YES;
}
Expand All @@ -69,7 +76,7 @@ - (void)feedDownloadSuccessful:(ZSURLConnectionDelegate*)delegate
DLog(@"success!");

NSError *error = nil;
GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:[delegate data] options:0 error:&error];
document = [[GDataXMLDocument alloc] initWithData:[delegate data] options:0 error:&error];
ZAssert(!error || document, @"Error parsing xml: %@", error);

DLog(@"document %@", document);
Expand All @@ -86,6 +93,14 @@ - (void)feedDownloadSuccessful:(ZSURLConnectionDelegate*)delegate
NSURL *url = [NSURL URLWithString:urlString];
ZAssert(url, @"Bad url: %@", urlString);
[cacheRequest addObject:url];

GDataXMLElement *mediaThumbnail = [[item elementsForName:@"media:thumbnail"] lastObject];
ZAssert(mediaThumbnail, @"Failed to find media thumbnail: %@", item);

NSString *thumbnailURLString = [[mediaThumbnail attributeForName:@"url"] stringValue];
NSURL *thumbnailURL = [NSURL URLWithString:thumbnailURLString];
ZAssert(thumbnailURL, @"Bad URL: %@", thumbnailURLString);
[cacheRequest addObject:thumbnailURL];
}

[assetManager queueAssetsForRetrievalFromURLSet:cacheRequest];
Expand All @@ -95,12 +110,16 @@ - (void)feedDownloadSuccessful:(ZSURLConnectionDelegate*)delegate
id root = [[navController viewControllers] objectAtIndex:0];
[root populateWithXMLItems:items];

MCRelease(document);
}

- (void)feedDownloadFailure:(ZSURLConnectionDelegate*)error
{
ALog(@"Failure: %@", error);
}

- (void)dealloc
{
MCRelease(document);
[super dealloc];
}
@end
6 changes: 5 additions & 1 deletion AssetManagerTest/Classes/RootViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

@interface RootViewController : UITableViewController
#import "ZSAssetManager.h"

@interface RootViewController : UITableViewController

@property (readwrite, retain) ZSAssetManager *assetManager;

- (void)populateWithXMLItems:(NSArray*)items;

Expand Down
42 changes: 35 additions & 7 deletions AssetManagerTest/Classes/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ @interface RootViewController()
@implementation RootViewController

@synthesize xmlItems;
@synthesize assetManager;

- (void)viewDidLoad
{
[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imageDownloadComplete:) name:kImageDownloadComplete object:[self assetManager]];
}

- (void)populateWithXMLItems:(NSArray*)items
Expand All @@ -49,6 +52,11 @@ - (void)populateWithXMLItems:(NSArray*)items
[[self tableView] reloadData];
}

- (void)imageDownloadComplete:(NSNotification *)notification
{
[[self tableView] reloadData];
}

#pragma mark -
#pragma mark UITableViewDatasource

Expand All @@ -65,15 +73,35 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}

// GDataXMLElement *item = [[self xmlItems] objectAtIndex:[indexPath row]];
// GDataXMLElement *title = [[item elementsForName:@"title"] lastObject];
// if (!title) {
// [[cell textLabel] setText:@"Untitled"];
// } else {
// [[cell textLabel] setText:[title stringValue]];
// }
GDataXMLElement *item = [[self xmlItems] objectAtIndex:[indexPath row]];
GDataXMLElement *title = [[item elementsForName:@"title"] lastObject];
if (!title) {
[[cell textLabel] setText:@"Untitled"];
} else {
[[cell textLabel] setText:[title stringValue]];
}

GDataXMLElement *mediaThumbnail = [[item elementsForName:@"media:thumbnail"] lastObject];
ZAssert(mediaThumbnail, @"Failed to find media thumbnail: %@", item);

NSString *thumbnailURLString = [[mediaThumbnail attributeForName:@"url"] stringValue];
NSURL *thumbnailURL = [NSURL URLWithString:thumbnailURLString];
[[cell imageView] setImage:[assetManager imageForURL:thumbnailURL]];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark -
#pragma mark Memory management
- (void)dealloc
{
[xmlItems release];
[assetManager release];
[super dealloc];
}
@end
9 changes: 9 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

In this repository is code that we share between many projects that we work on. It is licensed under the BSD license and is free to use as you wish.

## About this fork ##

This fork makes the following changes to ZSURLConnectionDelegate:

* Incoming data is saved to a file rather than kept in memory, which is useful if you're expecting a large download.
* It's possible to initialize ZSURLConnectionDelegate with an NSURLRequest instead of an NSURL, which is useful if you need to set custom HTTP headers on the request or want to provide a POST body.
* API has been added to optionally support self-signed HTTPS certificates for all hosts or for specific hosts.
* A userInfo parameter and some convenience constructors have been added.

## Prefix.pch ##

You will probably find macros in this code that does not compile. The reason is that we have several macros that we add to our Prefix.pch file upon project creation. Those macros are as follows:
Expand Down
1 change: 1 addition & 0 deletions ZSReachability.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>

typedef enum {
NotReachable = 0,
Expand Down
12 changes: 11 additions & 1 deletion ZSURLConnectionDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ void decrementNetworkActivity(id sender);
@property (nonatomic, assign, getter=isVerbose) BOOL verbose;
@property (nonatomic, assign, getter=isDone) BOOL done;

@property (nonatomic, readonly) NSMutableData *data;
@property (nonatomic, readonly) NSData *data;

@property (nonatomic, retain) id object;
@property (nonatomic, retain) NSString *filePath;
@property (nonatomic, retain) NSURL *myURL;
@property (nonatomic, retain) NSHTTPURLResponse *response;
@property (readonly) NSInteger HTTPStatus;
@property (nonatomic, retain) id delegate;

@property (nonatomic, assign) SEL successSelector;
Expand All @@ -56,6 +57,15 @@ void decrementNetworkActivity(id sender);
@property (nonatomic, assign) NSTimeInterval startTime;
@property (nonatomic, assign) NSTimeInterval duration;

@property (nonatomic, assign) BOOL acceptSelfSignedCertificates;
@property (nonatomic, copy) NSArray *acceptSelfSignedCertificatesFromHosts;

@property (readwrite, retain) id userInfo;

- (id)initWithRequest:(NSURLRequest *)newRequest delegate:(id)delegate;
- (id)initWithURL:(NSURL*)aURL delegate:(id)delegate;

+ (id)operationWithRequest:(NSURLRequest *)newRequest delegate:(id)aDelegate;
+ (id)operationWithURL:(NSURL *)aURL delegate:(id)aDelegate;

@end
Loading