Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在phonegap中压缩ios图像插件_Javascript_Jquery_Ios_Cordova - Fatal编程技术网

Javascript 在phonegap中压缩ios图像插件

Javascript 在phonegap中压缩ios图像插件,javascript,jquery,ios,cordova,Javascript,Jquery,Ios,Cordova,我是ios新手,在ios中为phonegap构建压缩图像插件。我不知道如何在javascript中调用压缩图像方法。我的代码是Plugin.h文件 - (void) cordovaCompressimg:(CDVInvokedUrlCommand *)command; Plugin.m文件 - (void) cordovaCompressimg:(CDVInvokedUrlCommand *)command { UIImage *sourceImage ; NSStri

我是ios新手,在ios中为phonegap构建压缩图像插件。我不知道如何在javascript中调用压缩图像方法。我的代码是Plugin.h文件

- (void) cordovaCompressimg:(CDVInvokedUrlCommand *)command;
Plugin.m文件

- (void) cordovaCompressimg:(CDVInvokedUrlCommand *)command 
 {
     UIImage *sourceImage ;
     NSString *compimg =[self UIImageToBaseSixtyFour];
CDVPluginResult *pluginResult = [ CDVPluginResult
                             resultWithStatus    : CDVCommandStatus_OK
                             NSData : compimg
                             ];

 [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}


 -(NSData *)UIImageToBaseSixtyFour
  {
    UIImage *sourceImage ;
    NSData *imageData = UIImageJPEGRepresentation(sourceImage, 1.0);

    NSString *base64 = [NSString stringWithFormat:@"%@",[UIImageJPEGRepresentation(sourceImage, 0.95) base64EncodedString]];

    return base64;
}
plugin.js文件

window.showimg = function(cimg, callback) {
           cordova.exec(callback, function(err) {
          callback('Nothing to echo.');
          }, "PhonegapPlugin", "cordovaGetCurrentDate", [cimg]);
 };
我在index.html中的调用函数是

        function showCompressimg() {
                  window.showimg("", function(echoValue) 
                  {
                       alert(echoValue);

                  });
        }
插件被调用,但图像为空。输出为空。源图像未通过。有人能帮我吗,
提前感谢

您正确地传递了源图像,但没有检索在objective-c代码中的参数中传递的图像。无论何时通过插件Javascript传递任何参数,这些参数都存储在CDVInvokedUrlCommand实例命令中。所以你可以像这样修改你的代码-

- (void) cordovaCompressimg:(CDVInvokedUrlCommand *)command 
 {
     //Arguments are passed in an Array. Source Image is present at Index 0
     UIImage *sourceImage  = [command argumentAtIndex:0];
     NSString *compimg =[self UIImageToBaseSixtyFour:sourceImage];
CDVPluginResult *pluginResult = [ CDVPluginResult
                             resultWithStatus    : CDVCommandStatus_OK
                             NSData : compimg
                             ];

 [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}


 -(NSData *)UIImageToBaseSixtyFour:(UIImage *)img
  {
    //UIImage *sourceImage ;
    NSData *imageData = UIImageJPEGRepresentation(img, 1.0);

    NSString *base64 = [NSString stringWithFormat:@"%@",[UIImageJPEGRepresentation(img, 0.95) base64EncodedString]];

    return base64;
}