【发布时间】:2016-03-10 19:23:44
【问题描述】:
我正在使用从 base64 到字符串的转换,而我需要它作为 iOS 本机插件中的图像文件路径
在 android 中这样的东西将位图转换为文件我需要在 iOS 中替代它
private String convertBitmapToFile(Bitmap photo)
由于我的base64到字符串的代码转换没有调用回调方法“profileBase64Callback”
plugin call://here citizen.profileImage is in base64 format
myPlugin.convertToFile("profileBase64Callback", citizen.profileImage, function(){ }, function(){ });
Nativeplugin.m
- (void)convertToFile:(CDVInvokedUrlCommand *)command{
NSDictionary* options = [[NSDictionary alloc]init];
if ([command.arguments count] > 0) {
options = [command argumentAtIndex:0];
NSString *base64Data =[options objectForKey:@"base64"];
NSLog(@"strttrtr :%@", base64Data);
}
NSData* data = [[NSData alloc] initWithBase64EncodedString: base64Data options:0];
NSString *strCOnvert = [NSString base64StringFromData:data length:[data length]];//Instead of this string I want decoded format(file path) to send to javascript Or if any other format which fixes my issue
dispatch_async(dispatch_get_main_queue(), ^{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:strCOnvert];
[pluginResult setKeepCallbackAsBool:true];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", @"profileBase64Callback", strCOnvert];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
});
调用一个javascript方法来执行:
//Need this imageURI after conversion which I am unable to convert
function profileBase64Callback(imageURI){
console.log("profileImage path " );
//updating to database
updateCitizenValue("profileImage", imageURI);
setTimeout(getCitizen(function(citizenVal){
}), 5000);
}//this method is not called due to error in conversion.
谁能告诉我我哪里出错了..尝试将base64格式的图像解码为实际文件
【问题讨论】:
-
如果我在 NSString * jsCallBack = [NSString stringWithFormat:@"%@(%@);", @"profileBase64Callback", @""]; 中发送空数据而不是上面代码中的 strCONvert ,而不是我的回调方法被称为 as..console==citizenVal.profileImage : undefined
标签: javascript ios base64 decode cordova-plugins