Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide success and error callbacks, and the "Not an image" error. #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"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"
]
},
"repository": {
"type": "git",
"url": "https://github.com/sarriaroman/photoviewer"
"url": "https://github.com/Hypher/photoviewer"
},
"keywords": [
"cordova",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8' ?>
<plugin id="com-sarriaroman-photoviewer" version="1.1.10" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="com-sarriaroman-photoviewer-fix" version="1.1.10" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>PhotoViewer</name>
<description>This plugin is intended to show a picture from an URL into a Photo Viewer with zoom features.</description>
<js-module name="PhotoViewer" src="www/PhotoViewer.js">
Expand Down
24 changes: 15 additions & 9 deletions src/ios/PhotoViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions www/PhotoViewer.js
Original file line number Diff line number Diff line change
@@ -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 = '';
}
Expand All @@ -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]);
};