Browse Source

Fix crash in iOS 6 when attempting to download or upload a file

Signed-off-by: Gleb Pinigin <gpinigin@gmail.com>
Marc Etcheverry 11 years ago
parent
commit
a38740bb64
2 changed files with 15 additions and 4 deletions
  1. 8 2
      Sources/VLCDownloadViewController.m
  2. 7 2
      Sources/VLCHTTPUploaderController.m

+ 8 - 2
Sources/VLCDownloadViewController.m

@@ -184,11 +184,17 @@
 
         if (downloadWasStarted) {
             if (!_backgroundTaskIdentifier || _backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
-                _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"VLCDownloader" expirationHandler:^{
+                dispatch_block_t expirationHandler = ^{
                     APLog(@"Downloads were interrupted after being in background too long, time remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
                     [[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
                     _backgroundTaskIdentifier = 0;
-                }];
+                };
+
+                if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginBackgroundTaskWithName:expirationHandler:)]) {
+                    _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"VLCDownloader" expirationHandler:expirationHandler];
+                } else {
+                    _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
+                }
             }
         }
 

+ 7 - 2
Sources/VLCHTTPUploaderController.m

@@ -55,11 +55,16 @@
 {
     if (self.httpServer.isRunning) {
         if (!_backgroundTaskIdentifier || _backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
-            _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"VLCUploader" expirationHandler:^{
+            dispatch_block_t expirationHandler = ^{
                 [self changeHTTPServerState:NO];
                 [[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
                 _backgroundTaskIdentifier = 0;
-            }];
+            };
+            if ([[UIApplication sharedApplication] respondsToSelector:@selector(beginBackgroundTaskWithName:expirationHandler:)]) {
+                _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"VLCUploader" expirationHandler:expirationHandler];
+            } else {
+                _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:expirationHandler];
+            }
         }
     }
 }