aflx/pg_downloader_plugin_ios — Issue #3: Parallel downloads
Author: javray
Created: 2011-11-28 21:02:38+00:00
State: open

Hello Alex,

I´m using your plugin to download some images in parallel to cache them. I've realised that only fires the last image callback. I've put some debug in your code and i've seen that the callbackID is always the same for all the calls, the last image callbackID.

For fix that I made some changes in your code, hope this helps you to fix that problem, I only write the changes:

Downloader.h:

Line 28:

(-) -(void) success:(NSMutableString*)filePath;
(+) -(void) success:(NSMutableArray*)paramArray;

Line 29:

(-) -(void) fail:(NSMutableString*)errorStr;
(+) -(void) fail:(NSMutableArray*)paramArray;

Downloader.m:

Line 34:

(-) self.callbackID = [paramArray pop];
(+) self.callbackID = [paramArray objectAtIndex:0];

Line 47-49:
(-)
NSString * sourceUrl = [paramArray objectAtIndex:0];
NSString * dirName = [paramArray objectAtIndex:1];
NSString * fileName = [paramArray objectAtIndex:2];
(+)
NSString * cid = [paramArray objectAtIndex;0];
NSString * sourceUrl = [paramArray objectAtIndex:1];
NSString * dirName = [paramArray objectAtIndex:2];
NSString * fileName = [paramArray objectAtIndex:3];

Line 66:
(-)	[self performSelectorOnMainThread:@selector(fail:) withObject:[error description] waitUntilDone:YES];
(+)	[self performSelectorOnMainThread:@selector(fail:) withObject:[NSMutableArray arrayWithObjects:[error description], cid, nil] waitUntilDone:YES];

Line 69:
(-)	[self performSelectorOnMainThread:@selector(success:) withObject:filePath waitUntilDone:YES];
(+) [self performSelectorOnMainThread:@selector(success:) withObject:[NSMutableArray arrayWithObjects:filePath, cid, nil] waitUntilDone:YES];

Line 76:
(-)	[self performSelectorOnMainThread:@selector(fail:) withObject:[error description] waitUntilDone:YES];
(+)	[self performSelectorOnMainThread:@selector(fail:) withObject:[NSMutableArray arrayWithObjects:[error description], cid, nil] waitUntilDone:YES];

Line 85:
(-) -(void) success:(NSMutableString *)filePath {
(+) -(void) success:(NSMutableArray *)paramArray {

Line 87:
(+)
NSString * filePath = [paramArray objectAtIndex:0];
NSString * cid = [paramArray objectAtIndex:1];

Line 90:
(-) [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
(+) [self writeJavascript: [pluginResult toSuccessCallbackString:cid]];

Line 96:
(-) -(void) fail:(NSMutableString *)errorStr {
(+) -(void) fail:(NSMutableArray *)paramArray {

Line 98:
(+)
NSString * errorStr = [paramArray objectAtIndex:0];
NSString * cid = [paramArray objectAtIndex:1];

Line 101:
(-) [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
(+) [self writeJavascript: [pluginResult toErrorCallbackString:cid]];

Once again, thanks for your plugin.

Best regards,

Javray