You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/05/12 03:09:14 UTC

ios commit: Fixes CB-684 - Not enough time for background execution of WebSQL/LocalStorage backup (when app goes to the background)

Updated Branches:
  refs/heads/master a27f4b374 -> d3ac2aaa2


Fixes CB-684 - Not enough time for background execution of WebSQL/LocalStorage backup (when app goes to the background)


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/d3ac2aaa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/d3ac2aaa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/d3ac2aaa

Branch: refs/heads/master
Commit: d3ac2aaa257aaf369f59bfecc53473578bc276a6
Parents: a27f4b3
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri May 11 18:09:03 2012 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri May 11 18:09:03 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVLocalStorage.m |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/d3ac2aaa/CordovaLib/Classes/CDVLocalStorage.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocalStorage.m b/CordovaLib/Classes/CDVLocalStorage.m
index 0fe9dc6..05ab034 100644
--- a/CordovaLib/Classes/CDVLocalStorage.m
+++ b/CordovaLib/Classes/CDVLocalStorage.m
@@ -293,12 +293,27 @@
 
 - (void) onResignActive
 {
-    [self backup:nil withDict:nil];    
+    if ([[UIDevice currentDevice] isMultitaskingSupported]) 
+    {
+        __block UIBackgroundTaskIdentifier backgroundTaskID = UIBackgroundTaskInvalid;
+        
+        backgroundTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
+            NSLog(@"Background task to backup WebSQL/LocalStorage expired.");
+        }];
+        
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            [self backup:nil withDict:nil];
+            
+            [[UIApplication sharedApplication] endBackgroundTask: backgroundTaskID];
+            backgroundTaskID = UIBackgroundTaskInvalid;
+        });
+    }
 }
 
 - (void) onAppTerminate
 {
-    [self backup:nil withDict:nil];    
+    [self onResignActive];    
 }
 
 #pragma mark -