diff --git a/package.json b/package.json index 91b9a3b..49ea1fe 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "com-sarriaroman-photoviewer", + "name": "com-sarriaroman-photoviewer-fix", "version": "1.1.10", "description": "This plugin is intended to show a picture from an URL into a Photo Viewer with zoom features.", "cordova": { - "id": "com-sarriaroman-photoviewer", + "id": "com-sarriaroman-photoviewer-fix", "platforms": [ "android", "ios" @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/sarriaroman/photoviewer" + "url": "https://github.com/Hypher/photoviewer" }, "keywords": [ "cordova", diff --git a/plugin.xml b/plugin.xml index ee1c0ee..2627400 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + PhotoViewer This plugin is intended to show a picture from an URL into a Photo Viewer with zoom features. diff --git a/src/ios/PhotoViewer.m b/src/ios/PhotoViewer.m index 4eb5366..67b1dd9 100644 --- a/src/ios/PhotoViewer.m +++ b/src/ios/PhotoViewer.m @@ -53,8 +53,7 @@ - (void)show:(CDVInvokedUrlCommand*)command [activityIndicator startAnimating]; - - CDVPluginResult* pluginResult = nil; + NSString* url = [command.arguments objectAtIndex:0]; NSString* title = [command.arguments objectAtIndex:1]; @@ -73,14 +72,16 @@ - (void)show:(CDVInvokedUrlCommand*)command [activityIndicator stopAnimating]; [self.docInteractionController presentPreviewAnimated:YES]; }); + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId]; + } + else { + [activityIndicator stopAnimating]; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not an image"] callbackId:command.callbackId]; } }]; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId]; } - - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (NSURL *)localFileURLForImage:(NSString *)image @@ -96,11 +97,16 @@ - (NSURL *)localFileURLForImage:(NSString *)image NSData *data = [NSData dataWithContentsOfURL:fileURL]; if( data ) { - fileURL = [[tmpDirURL URLByAppendingPathComponent:filename] URLByAppendingPathExtension:[self contentTypeForImageData:data]]; + NSString *contentType = [self contentTypeForImageData:data]; + if(contentType) { + fileURL = [[tmpDirURL URLByAppendingPathComponent:filename] URLByAppendingPathExtension:contentType]; - [[NSFileManager defaultManager] createFileAtPath:[fileURL path] contents:data attributes:nil]; + [[NSFileManager defaultManager] createFileAtPath:[fileURL path] contents:data attributes:nil]; - return fileURL; + return fileURL; + } else { + return nil; + } } else { return nil; } diff --git a/www/PhotoViewer.js b/www/PhotoViewer.js index f391442..4c7aae2 100644 --- a/www/PhotoViewer.js +++ b/www/PhotoViewer.js @@ -1,6 +1,6 @@ var exec = require('cordova/exec'); -exports.show = function(url, title, options) { +exports.show = function(url, title, options, successCallback, errorCallback) { if( title == undefined ) { title = ''; } @@ -9,5 +9,5 @@ exports.show = function(url, title, options) { options = {}; } - exec(function(){}, function(){}, "PhotoViewer", "show", [url, title, options]); + exec(successCallback, errorCallback, "PhotoViewer", "show", [url, title, options]); };