Hi
I’m using this plugin : https://github.com/Nomia/ImgDownloader.git
It downloads a file and save it on the device. It works in my emulator (sadly not in Ionic View … but that’s different story).
So as I said, it works … it downloads and saves the image. But It doesn’t give me a reference (file location/name or mediaID) to the new file. I’ve placed a issue ticket in GIT, but I don’t know if the developer is still developing.
So with my little knowledge of Objective C I’ve been digging in the source code and saw this
- (void)downloadWithUrl:(CDVInvokedUrlCommand*)command {
CDVPluginResult *pluginResult = nil;
NSURL *url = [NSURL URLWithString:[command.arguments objectAtIndex:0]];
NSData *args = [NSData dataWithContentsOfURL:url];
if (args != nil && [args length] > 0) {
@try
{
UIImage *image = [UIImage imageWithData:args];
NSData *imgdata = UIImagePNGRepresentation(image);
UIImage *image2 = [UIImage imageWithData:imgdata];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"success"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@catch (NSException *exception) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}
}
My question … can somebody alter the code so it will return the file location + name and mediaID