【发布时间】:2014-07-21 07:03:07
【问题描述】:
我正在为 ios 尝试一个 cordova 项目。 我的日志中有一个资产 url,我尝试在我的代码中使用该 url,它工作正常。 但是,我需要该资产 URL 作为从目标 C 到 javascript 的返回值。
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command{
self.callbackId = command.callbackId;
NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
UIImage *viewImage = image; // --- mine was made from drawing context
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"error");
} else {
NSLog(@"url %@", assetURL);
}
}];
[library release];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
// Was there an error?
if (error != NULL)
{
// Show error message...
NSLog(@"ERROR: %@",error);
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
[self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]];
}
else // No errors
{
// Show message image successfully saved
NSLog(@"IMAGE SAVED!");
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"];
[self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]];
}
}
这里.... 这段代码给了我日志....
NSLog(@"url %@", assetURL);
我想将此 assetURL 作为我的 javascript 的返回值,在哪里调用此函数...
我在这里呆了一个星期......
帮我解脱...
提前谢谢.....
【问题讨论】:
标签: javascript ios objective-c cordova alassetslibrary