You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/27 21:12:20 UTC
ios commit: [CB-2190] Allow FileTransfer uploads to continue in
background
Updated Branches:
refs/heads/master 43edb033b -> 7aa260741
[CB-2190] Allow FileTransfer uploads to continue in background
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/7aa26074
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/7aa26074
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/7aa26074
Branch: refs/heads/master
Commit: 7aa2607416c4a3981e7274e825457bacdcbc040b
Parents: 43edb03
Author: Ian Clelland <ic...@chromium.org>
Authored: Tue Mar 19 11:02:32 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 27 16:12:09 2013 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVFileTransfer.h | 1 +
CordovaLib/Classes/CDVFileTransfer.m | 10 ++++++++++
2 files changed, 11 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7aa26074/CordovaLib/Classes/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.h b/CordovaLib/Classes/CDVFileTransfer.h
index 404220b..39a21e0 100644
--- a/CordovaLib/Classes/CDVFileTransfer.h
+++ b/CordovaLib/Classes/CDVFileTransfer.h
@@ -53,6 +53,7 @@ extern NSString* const kOptionsKeyCookie;
AndHttpStatus:(int)httpStatus
AndBody:(NSString*)body;
@property (readonly) NSMutableDictionary* activeTransfers;
+@property (nonatomic, assign) UIBackgroundTaskIdentifier backgroundTaskID;
@end
@interface CDVFileTransferDelegate : NSObject {}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7aa26074/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index bbb601d..3355a12 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -216,6 +216,12 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
CFStreamCreateBoundPair(NULL, &readStream, &writeStream, kStreamBufferSize);
[req setHTTPBodyStream:CFBridgingRelease(readStream)];
+ self.backgroundTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
+ [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskID];
+ self.backgroundTaskID = UIBackgroundTaskInvalid;
+ NSLog(@"Background task to upload media finished.");
+ }];
+
[self.commandDelegate runInBackground:^{
if (CFWriteStreamOpen(writeStream)) {
NSData* chunks[] = {postBodyBeforeFile, fileData, postBodyAfterFile};
@@ -509,6 +515,10 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
// remove connection for activeTransfers
[command.activeTransfers removeObjectForKey:objectId];
+
+ // remove background id task in case our upload was done in the background
+ [[UIApplication sharedApplication] endBackgroundTask:self.command.backgroundTaskID];
+ self.command.backgroundTaskID = UIBackgroundTaskInvalid;
}
- (void)cancelTransferWithError:(NSURLConnection*)connection errorMessage:(NSString*)errorMessage