Skip to content

Commit

Permalink
updated for iOS 5 ; removed extranous code ; removed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterHillegas committed Aug 21, 2012
1 parent 443dcfc commit ec8e782
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 219 deletions.
Binary file added External/.DS_Store
Binary file not shown.
110 changes: 3 additions & 107 deletions HelloMapKitWorld.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0440"
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,7 +23,7 @@
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
Expand All @@ -38,7 +38,6 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "YES"
debugDocumentVersioning = "YES"
enableOpenGLFrameCaptureMode = "0"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
Expand Down
18 changes: 2 additions & 16 deletions HelloMapKitWorld/FLLocationDownloader.h
Expand Up @@ -8,24 +8,10 @@

#import <Foundation/Foundation.h>

#import "ASIHTTPRequest.h"
@interface FLLocationDownloader : NSObject

@interface FLLocationDownloader : NSObject {
NSOperationQueue *operationQueue;
NSPersistentStoreCoordinator *storeCoordinator;
NSManagedObjectContext *mainThreadContext;
}

@property (nonatomic, strong) NSOperationQueue *operationQueue;
@property (nonatomic, strong) NSPersistentStoreCoordinator *storeCoordinator;
@property (nonatomic, strong) NSManagedObjectContext *mainThreadContext;

- (id)initWithOperationQueue:(NSOperationQueue *)aOperationQueue withStoreCoordinator:(NSPersistentStoreCoordinator *)aCoordinator withMainThreadContext:(NSManagedObjectContext *)aMainThreadContext;
- (id)initWithOperationQueue:(NSOperationQueue *)aOperationQueue withMainThreadContext:(NSManagedObjectContext *)aMainThreadContext;

- (void)start;

- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
- (void)parseResponse:(ASIHTTPRequest *)completedRequest;

@end
54 changes: 23 additions & 31 deletions HelloMapKitWorld/FLLocationDownloader.m
Expand Up @@ -7,20 +7,24 @@
//

#import "FLLocationDownloader.h"
#import "FLLocation.h"

#import "FLLocationParser.h"
@interface FLLocationDownloader ()

@implementation FLLocationDownloader
@property (nonatomic, strong) NSOperationQueue *operationQueue;
@property (nonatomic, strong) NSManagedObjectContext *privateContext;

@end

@synthesize operationQueue;
@synthesize storeCoordinator;
@synthesize mainThreadContext;
@implementation FLLocationDownloader

- (id)initWithOperationQueue:(NSOperationQueue *)aOperationQueue withStoreCoordinator:(NSPersistentStoreCoordinator *)aCoordinator withMainThreadContext:(NSManagedObjectContext *)aMainThreadContext {
- (id)initWithOperationQueue:(NSOperationQueue *)aOperationQueue withMainThreadContext:(NSManagedObjectContext *)aMainThreadContext {
if ((self = [super init])) {
self.operationQueue = aOperationQueue;
self.storeCoordinator = aCoordinator;
self.mainThreadContext = aMainThreadContext;

NSManagedObjectContext *__privateContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
self.privateContext = __privateContext;
[self.privateContext setParentContext:aMainThreadContext];
}
return self;
}
Expand All @@ -29,29 +33,17 @@ - (void)start {
NSLog(@"Request Locations: %@", kAssetURL);

NSURL *url = [NSURL URLWithString:kAssetURL];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];

[operationQueue addOperation:request];
}

- (void)parseResponse:(ASIHTTPRequest *)completedRequest {
FLLocationParser *requestParser = [[FLLocationParser alloc] initWithCoordinator:self.storeCoordinator andMainThreadContext:self.mainThreadContext];
requestParser.completedRequest = completedRequest;
[self.operationQueue addOperation:requestParser];
}

- (void)requestFinished:(ASIHTTPRequest *)request {
if (request.responseStatusCode == 200) {
[self parseResponse:request];
} else {
NSLog(@"%@ Download Response Code Was Not 200: %d", request.url, request.responseStatusCode);
}
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
id parsedResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
id locations = [parsedResponse valueForKey:@"locations"];

//send data to method that will create and save managed objects
[self.privateContext performBlockAndWait:^{
[FLLocation batchUpdateOrCreateWithArray:locations inContext:self.privateContext];
}];
});
}];
}

- (void)requestFailed:(ASIHTTPRequest *)request {
NSLog(@"Download Error: %@", [request error]);
}


@end
33 changes: 25 additions & 8 deletions HelloMapKitWorld/HelloMapKitWorld-Info.plist
Expand Up @@ -11,10 +11,17 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIconFiles</key>
<array>
<string>Icon.png</string>
<string>Icon@2x.png</string>
</array>
<array/>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array/>
<key>UIPrerenderedIcon</key>
<true/>
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>com.hanchorllc.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -24,20 +31,30 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>UIPrerenderedIcon</key>
<true/>
<key>UIStatusBarTintParameters</key>
<dict>
<key>UINavigationBar</key>
<dict>
<key>Style</key>
<string>UIBarStyleDefault</string>
<key>Translucent</key>
<false/>
</dict>
</dict>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIPrerenderedIcon</key>
<true/>
</dict>
</plist>
3 changes: 2 additions & 1 deletion HelloMapKitWorld/HelloMapKitWorldAppDelegate.m
Expand Up @@ -23,6 +23,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];

return YES;
Expand Down Expand Up @@ -103,7 +104,7 @@ - (NSManagedObjectContext *)managedObjectContext {

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
__managedObjectContext = [[NSManagedObjectContext alloc] init];
__managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[__managedObjectContext setPersistentStoreCoordinator:coordinator];
}

Expand Down
32 changes: 3 additions & 29 deletions HelloMapKitWorld/MapViewController.m
Expand Up @@ -11,35 +11,17 @@
#import "FLLocation.h"

@interface MapViewController ()

- (void)populateMapWithLocations;

@end

@implementation MapViewController

@synthesize locationMapView=_locationMapView;
@synthesize locations=_locations;
@synthesize selectedIndex;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)dealloc {
self.locationMapView.delegate = nil;
[self.locationMapView removeAnnotations:self.locationMapView.annotations];


}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
[self.locationMapView removeAnnotations:self.locationMapView.annotations];
}

#pragma mark - View lifecycle
Expand All @@ -53,14 +35,6 @@ - (void)viewDidLoad {
[self populateMapWithLocations];
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;

self.locationMapView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Expand Down
28 changes: 4 additions & 24 deletions HelloMapKitWorld/RootViewController.m
Expand Up @@ -20,11 +20,6 @@ - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPa

@implementation RootViewController

@synthesize fetchedResultsController=__fetchedResultsController;
@synthesize managedObjectContext=__managedObjectContext;
@synthesize networkQueue=_networkQueue;
@synthesize locationDownloader=_locationDownloader;

- (void)viewDidLoad {
[super viewDidLoad];

Expand Down Expand Up @@ -93,21 +88,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[self.navigationController pushViewController:mapView animated:YES];
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];

// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
FLLocation *managedObject = (FLLocation *)[self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = managedObject.name;
Expand All @@ -118,7 +98,7 @@ - (void)requestLocationDownloads {

[MBProgressHUD showHUDAddedTo:self.view animated:YES];

FLLocationDownloader *aLocationDownloader = [[FLLocationDownloader alloc] initWithOperationQueue:self.networkQueue withStoreCoordinator:[self.managedObjectContext persistentStoreCoordinator] withMainThreadContext:self.managedObjectContext];
FLLocationDownloader *aLocationDownloader = [[FLLocationDownloader alloc] initWithOperationQueue:self.networkQueue withMainThreadContext:self.managedObjectContext];
self.locationDownloader = aLocationDownloader;

[self.locationDownloader start];
Expand All @@ -127,8 +107,8 @@ - (void)requestLocationDownloads {
#pragma mark - Fetched results controller

- (NSFetchedResultsController *)fetchedResultsController {
if (__fetchedResultsController != nil) {
return __fetchedResultsController;
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}

/*
Expand Down Expand Up @@ -161,7 +141,7 @@ - (NSFetchedResultsController *)fetchedResultsController {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

return __fetchedResultsController;
return _fetchedResultsController;
}

#pragma mark - Fetched results controller delegate
Expand Down

0 comments on commit ec8e782

Please sign in to comment.