Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

Commit

Permalink
Clean up app delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
dankimio committed Feb 23, 2017
1 parent 8897d37 commit afe16ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
45 changes: 17 additions & 28 deletions ZP/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,18 @@ - (BOOL) application:(UIApplication *)application
NSLog(@"url: %@", url);
}];

// [DDLog addLogger:[DDASLLogger sharedInstance]];
// [DDLog addLogger:[DDTTYLogger sharedInstance]];

[Fabric with:@[[Crashlytics class]]];
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;

[GMSServices provideAPIKey:ZPPGMSApiKey];
[LMGeocoder sharedInstance].googleAPIKey = ZPPGMSApiKey;

if (IS_OS_8_OR_LATER) {
[application
registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound |
UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge)
categories:nil]];
[application registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound |
UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge)
categories:nil]];

[application registerForRemoteNotifications];
}
Expand All @@ -62,24 +58,12 @@ - (BOOL) application:(UIApplication *)application
}

- (void)applicationWillResignActive:(UIApplication *)application {
// 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.
// 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.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
// 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.
// If your application supports background execution, this method is called instead of
// applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
Expand All @@ -90,7 +74,11 @@ - (void)applicationWillTerminate:(UIApplication *)application {
[self saveContext];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {

return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
Expand All @@ -112,8 +100,10 @@ - (NSManagedObjectModel *)managedObjectModel {
if (_managedObjectModel != nil) {
return _managedObjectModel;
}

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"ZP" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

return _managedObjectModel;
}

Expand All @@ -129,8 +119,8 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
NSURL *storeURL =
[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ZP.sqlite"];
NSError *error = nil;
NSString *failureReason =
@"There was an error creating or loading the application's saved data.";
NSString *failureReason = @"There was an error creating or loading the application's saved data.";

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
Expand Down Expand Up @@ -158,8 +148,7 @@ - (NSManagedObjectContext *)managedObjectContext {
if (!coordinator) {
return nil;
}
_managedObjectContext =
[[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
return _managedObjectContext;
}
Expand All @@ -170,6 +159,7 @@ - (void)saveContext {
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
NSError *error = nil;

if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
Expand All @@ -179,8 +169,7 @@ - (void)saveContext {

#pragma mark - Push notifications

- (void) application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[ZPPUserManager sharedInstance] setAPNsToken:deviceToken];
}

Expand Down
8 changes: 3 additions & 5 deletions ZP/UIButton+ZPPButtonCategory.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ - (void)stopIndication {
[v removeFromSuperview];
}
}

self.enabled = YES;
}

Expand All @@ -30,17 +31,14 @@ - (void)startIndicating {
- (void)startIndicatingWithType:(UIActivityIndicatorViewStyle)style {
[self stopIndication];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
UIActivityIndicatorView *v =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
UIActivityIndicatorView *v = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
[v startAnimating];

CGSize size = v.frame.size;

v.frame = CGRectMake(8, (self.frame.size.height - size.height) / 2.0, v.frame.size.width,
v.frame.size.height);
v.frame = CGRectMake(8, (self.frame.size.height - size.height) / 2.0, v.frame.size.width, v.frame.size.height);

[self addSubview:v];

self.enabled = NO;
}

Expand Down

0 comments on commit afe16ae

Please sign in to comment.