浏览代码

Prevent device from going to sleep during ongoing download processes (close #9062)

Felix Paul Kühne 12 年之前
父节点
当前提交
ee60693279

+ 6 - 2
AspenProject/VLCDropboxController.m

@@ -170,15 +170,19 @@
 - (void)networkRequestStarted
 {
     _outstandingNetworkRequests++;
-    if (_outstandingNetworkRequests == 1)
+    if (_outstandingNetworkRequests == 1) {
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
+        [UIApplication sharedApplication].idleTimerDisabled = YES;
+    }
 }
 
 - (void)networkRequestStopped
 {
     _outstandingNetworkRequests--;
-    if (_outstandingNetworkRequests == 0)
+    if (_outstandingNetworkRequests == 0) {
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+        [UIApplication sharedApplication].idleTimerDisabled = NO;
+    }
 }
 
 #pragma mark - VLC internal communication and delegate

+ 2 - 0
AspenProject/VLCHTTPFileDownloader.m

@@ -44,6 +44,7 @@
     } else {
         _downloadInProgress = YES;
         [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
+        [UIApplication sharedApplication].idleTimerDisabled = YES;
     }
 }
 
@@ -128,6 +129,7 @@
 {
     _downloadInProgress = NO;
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+    [UIApplication sharedApplication].idleTimerDisabled = NO;
 
     [self.delegate downloadEnded];
 }

+ 2 - 0
AspenProject/VLCHTTPUploaderController.m

@@ -284,6 +284,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
         storeFile = [NSFileHandle fileHandleForWritingAtPath:filePath];
         [uploadedFiles addObject: [NSString stringWithFormat:@"/upload/%@", filename]];
         [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
+        [UIApplication sharedApplication].idleTimerDisabled = YES;
     }
 }
 
@@ -301,6 +302,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
     [storeFile closeFile];
     storeFile = nil;
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
+    [UIApplication sharedApplication].idleTimerDisabled = NO;
 
     /* update media library when file upload was completed */
     VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;