Permalink
Browse files

use cancel when the app goes to background.

  • Loading branch information...
1 parent 8dd892f commit b736428fa25c3f0568d50cee1ac9f79bad03a20b @cvasilak cvasilak committed Mar 11, 2013
@@ -20,6 +20,8 @@
#import "AGLoginViewController.h"
#import "AGTasksViewController.h"
+#import "AGToDoAPIService.h"
+
@implementation AGAppDelegate
@synthesize window = _window;
@@ -32,42 +34,20 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.viewController = [[AGLoginViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
-
- /*
- AGTasksViewController *tasksViewController = [[AGTasksViewController alloc] initWithStyle:UITableViewStylePlain];
- self.navController = [[UINavigationController alloc] initWithRootViewController:tasksViewController];
- self.navController.toolbarHidden = NO;
-
- [self.window addSubview:self.navController.view];
- */
+
return YES;
}
-- (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
-{
- // 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.
-}
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ // inform runtime that we require additional time prior to suspending our app.
+ // When timeout expires, we cancel all pending operations (if any)
+ __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+ [[AGToDoAPIService sharedInstance] cancelAllOperations];
+
+ [application endBackgroundTask:bgTask];
+ bgTask = UIBackgroundTaskInvalid;
+ }];
}
@end
@@ -72,6 +72,8 @@
- (void) logout:(void (^)())success
failure:(void (^)(NSError *error))failure;
+- (void) cancelAllOperations;
+
+ (void)enrollUser:(NSDictionary *)userInfo
success:(void (^)())success
failure:(void (^)(NSError *error))failure;
@@ -279,6 +279,12 @@ - (void) logout:(void (^)())success
[_restAuthModule logout:success failure:failure];
}
+- (void) cancelAllOperations {
+ [_tasksPipe cancel];
+ [_tagsPipe cancel];
+ [_projectsPipe cancel];
+}
+
+ (void)enrollUser:(NSDictionary *)userInfo
success:(void (^)())success
failure:(void (^)(NSError *error))failure {

0 comments on commit b736428

Please sign in to comment.