|
@@ -37,6 +37,8 @@
|
|
|
WRRequestDownload *_FTPDownloadRequest;
|
|
|
NSTimeInterval _lastStatsUpdate;
|
|
|
CGFloat _averageSpeed;
|
|
|
+
|
|
|
+ UIBackgroundTaskIdentifier _backgroundTaskIdentifier;
|
|
|
}
|
|
|
@end
|
|
|
|
|
@@ -137,6 +139,8 @@
|
|
|
#pragma mark - download management
|
|
|
- (void)_triggerNextDownload
|
|
|
{
|
|
|
+ BOOL downloadWasStarted = NO;
|
|
|
+
|
|
|
if ([_currentDownloads count] > 0) {
|
|
|
[self.activityIndicator startAnimating];
|
|
|
NSString *downloadScheme = [_currentDownloads[0] scheme];
|
|
@@ -155,8 +159,11 @@
|
|
|
[_httpDownloader downloadFileFromURL:_currentDownloads[0]];
|
|
|
_humanReadableFilename = _httpDownloader.userReadableDownloadName;
|
|
|
}
|
|
|
- [_currentDownloads removeObjectAtIndex:0];
|
|
|
- [_currentDownloadFilename removeObjectAtIndex:0];
|
|
|
+
|
|
|
+ [_currentDownloads removeObjectAtIndex:0];
|
|
|
+ [_currentDownloadFilename removeObjectAtIndex:0];
|
|
|
+
|
|
|
+ downloadWasStarted = YES;
|
|
|
}
|
|
|
} else if ([downloadScheme isEqualToString:@"ftp"]) {
|
|
|
_currentDownloadType = kVLCDownloadViaFTP;
|
|
@@ -164,12 +171,30 @@
|
|
|
_humanReadableFilename = [_currentDownloads[0] lastPathComponent];
|
|
|
[_currentDownloads removeObjectAtIndex:0];
|
|
|
[_currentDownloadFilename removeObjectAtIndex:0];
|
|
|
+ downloadWasStarted = YES;
|
|
|
} else
|
|
|
APLog(@"Unknown download scheme '%@'", downloadScheme);
|
|
|
|
|
|
+
|
|
|
+ if (downloadWasStarted) {
|
|
|
+ if (!_backgroundTaskIdentifier || _backgroundTaskIdentifier == UIBackgroundTaskInvalid) {
|
|
|
+ _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"VLCDownloader" expirationHandler:^{
|
|
|
+ APLog(@"Downloads were interrupted after being in background too long, time remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
|
|
|
+ [[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
|
|
|
+ _backgroundTaskIdentifier = 0;
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[self _updateUI];
|
|
|
- } else
|
|
|
+ } else {
|
|
|
_currentDownloadType = 0;
|
|
|
+
|
|
|
+ if (_backgroundTaskIdentifier && _backgroundTaskIdentifier != UIBackgroundTaskInvalid) {
|
|
|
+ [[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
|
|
|
+ _backgroundTaskIdentifier = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (IBAction)cancelDownload:(id)sender
|