CB-6059 iOS: Stop FileTransfer.download doing IO on the UI thread.

Project: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/commit/49b4774e
Tree: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/tree/49b4774e
Diff: 
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/diff/49b4774e

Branch: refs/heads/master
Commit: 49b4774e7ecea3730fb060eafd0c7d8b7e98523a
Parents: a588236
Author: Jan Pittner <[email protected]>
Authored: Wed Feb 19 10:56:27 2014 -0500
Committer: Andrew Grieve <[email protected]>
Committed: Wed Feb 19 10:56:27 2014 -0500

----------------------------------------------------------------------
 src/ios/CDVFileTransfer.h |  1 +
 src/ios/CDVFileTransfer.m | 10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/49b4774e/src/ios/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.h b/src/ios/CDVFileTransfer.h
index 07feb85..ab95221 100644
--- a/src/ios/CDVFileTransfer.h
+++ b/src/ios/CDVFileTransfer.h
@@ -52,6 +52,7 @@ extern NSString* const kOptionsKeyCookie;
                                       AndTarget:(NSString*)target
                                   AndHttpStatus:(int)httpStatus
                                         AndBody:(NSString*)body;
+@property (nonatomic, strong) NSOperationQueue* queue;
 @property (readonly) NSMutableDictionary* activeTransfers;
 @end
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer/blob/49b4774e/src/ios/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFileTransfer.m b/src/ios/CDVFileTransfer.m
index 9125e2f..27e1204 100644
--- a/src/ios/CDVFileTransfer.m
+++ b/src/ios/CDVFileTransfer.m
@@ -412,13 +412,19 @@ static CFIndex WriteDataToStream(NSData* data, 
CFWriteStreamRef stream)
         [delegate cancelTransfer:delegate.connection];
     }];
 
-    delegate.connection = [NSURLConnection connectionWithRequest:req 
delegate:delegate];
+    delegate.connection = [[NSURLConnection alloc] initWithRequest:req 
delegate:delegate startImmediately:NO];
+
+    if (self.queue == nil) {
+        self.queue = [[NSOperationQueue alloc] init];
+    }
+    [delegate.connection setDelegateQueue:self.queue];
 
     if (activeTransfers == nil) {
         activeTransfers = [[NSMutableDictionary alloc] init];
     }
-
     [activeTransfers setObject:delegate forKey:delegate.objectId];
+
+    [delegate.connection start];
 }
 
 - (NSMutableDictionary*)createFileTransferError:(int)code 
AndSource:(NSString*)source AndTarget:(NSString*)target

Reply via email to