Playlist Generator  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
Playlist2/playlist2AppDelegate.m
Go to the documentation of this file.
00001 //
00002 //  playlist2AppDelegate.m
00003 //  Playlist2
00004 //
00005 //  Created by Max Woolf on 25/11/2011.
00006 //  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "playlist2AppDelegate.h"
00010 #import "IdentifyViewController.h"
00011 
00012 @implementation playlist2AppDelegate
00013 
00014 @synthesize window = _window;
00015 @synthesize viewController = _viewController;
00016 @synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
00017 @synthesize managedObjectContext = __managedObjectContext;
00018 @synthesize managedObjectModel = __managedObjectModel;
00019 
00020 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
00021 {    
00022     managedObjectContext = [self managedObjectContext];
00023     
00024 //    NSManagedObject *track = [[NSManagedObject alloc] initWithEntity:[NSEntityDescription entityForName:@"Track" inManagedObjectContext:__managedObjectContext] insertIntoManagedObjectContext:__managedObjectContext];
00025 //    [track setValue:@"Jack Johnson" forKey:@"artist"];
00026 //    [track setValue:@"Banana Pancakes" forKey:@"title"];
00027 //    [track setValue:@"SOHTBAY12A6701BF18" forKey:@"id"];
00028 //    
00029 //    NSError *error;
00030 //    if (![__managedObjectContext save:&error]) {
00031 //        NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
00032 //    }
00033     
00034     //[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
00035     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
00036     // Override point for customization after application launch.
00037     //self.viewController = [[playlist2ViewController alloc] initWithNibName:@"playlist2ViewController" bundle:nil];
00038     
00039     IdentifyViewController *viewController = [[IdentifyViewController alloc] init];
00040     UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:viewController];
00041     [navCon setNavigationBarHidden: YES];
00042     self.window.rootViewController = navCon;
00043     
00044     [self.window makeKeyAndVisible];
00045     return YES;
00046 }
00047 
00048 - (void)applicationWillResignActive:(UIApplication *)application
00049 {
00050     /*
00051      Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
00052      Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
00053      */
00054 }
00055 
00056 
00057 - (void)applicationDidEnterBackground:(UIApplication *)application
00058 {
00059     /*
00060      Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
00061      If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
00062      */
00063 }
00064 
00065 - (void)applicationWillEnterForeground:(UIApplication *)application
00066 {
00067     /*
00068      Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
00069      */
00070 }
00071 
00072 - (void)applicationDidBecomeActive:(UIApplication *)application
00073 {
00074     /*
00075      Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
00076      */
00077 }
00078 
00079 - (void)applicationWillTerminate:(UIApplication *)application
00080 {
00081     /*
00082      Called when the application is about to terminate.
00083      Save data if appropriate.
00084      See also applicationDidEnterBackground:.
00085      */
00086 }
00087 
00088 - (void)saveContext
00089 {
00090     NSError *error = nil;
00091     NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
00092     if (managedObjectContext != nil)
00093     {
00094         if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
00095         {
00096             /*
00097              Replace this implementation with code to handle the error appropriately.
00098              
00099              abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
00100              */
00101             NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
00102             abort();
00103         } 
00104     }
00105 }
00106 
00107 #pragma mark - Core Data stack
00108 
00113 - (NSManagedObjectContext *)managedObjectContext
00114 {
00115     if (__managedObjectContext != nil)
00116     {
00117         return __managedObjectContext;
00118     }
00119     
00120     NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
00121     if (coordinator != nil)
00122     {
00123         __managedObjectContext = [[NSManagedObjectContext alloc] init];
00124         [__managedObjectContext setPersistentStoreCoordinator:coordinator];
00125     }
00126     return __managedObjectContext;
00127 }
00128 
00133 - (NSManagedObjectModel *)managedObjectModel
00134 {
00135     if (__managedObjectModel != nil)
00136     {
00137         return __managedObjectModel;
00138     }
00139     NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Playlist2" withExtension:@"momd"];
00140     __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
00141     return __managedObjectModel;
00142 }
00143 
00148 - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
00149 {
00150     if (__persistentStoreCoordinator != nil)
00151     {
00152         return __persistentStoreCoordinator;
00153     }
00154     
00155     NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Playlist2.sqlite"];
00156     
00157     NSError *error = nil;
00158     __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
00159     if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
00160     {
00161         /*
00162          Replace this implementation with code to handle the error appropriately.
00163          
00164          abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
00165          
00166          Typical reasons for an error here include:
00167          * The persistent store is not accessible;
00168          * The schema for the persistent store is incompatible with current managed object model.
00169          Check the error message to determine what the actual problem was.
00170          
00171          
00172          If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
00173          
00174          If you encounter schema incompatibility errors during development, you can reduce their frequency by:
00175          * Simply deleting the existing store:
00176          [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
00177          
00178          * Performing automatic lightweight migration by passing the following dictionary as the options parameter: 
00179          [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
00180          
00181          Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
00182          
00183          */
00184         NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
00185         abort();
00186     }    
00187     
00188     return __persistentStoreCoordinator;
00189 }
00190 
00191 #pragma mark - Application's Documents directory
00192 
00196 - (NSURL *)applicationDocumentsDirectory
00197 {
00198     return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
00199 }
00200 
00201 
00202 @end