You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/02/12 04:14:33 UTC
[5/13] ios commit: [CB-2213] Added NATIVE_URI to getMetadata.
[CB-2213] Added NATIVE_URI to getMetadata.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/2af83b12
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/2af83b12
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/2af83b12
Branch: refs/heads/master
Commit: 2af83b12d13681991d721628f0cd6894a6a3b0d2
Parents: 5adf243
Author: Max Woghiren <ma...@gmail.com>
Authored: Wed Jan 16 12:40:06 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Feb 11 21:06:23 2013 -0500
----------------------------------------------------------------------
CordovaLib/Classes/CDVFile.m | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/2af83b12/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 171410f..8fee45a 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -480,11 +480,33 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
{
// arguments
NSString* argPath = [command.arguments objectAtIndex:0];
+ __block CDVPluginResult* result = nil;
- // return unsupported result for assets-library URLs
if ([argPath hasPrefix:kCDVAssetsLibraryPrefix]) {
- CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION messageAsString:@"getMetadata not supported for assets-library URLs."];
- [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+ // In this case, we need to use an asynchronous method to retrieve the file.
+ // Because of this, we can't just assign to `result` and send it at the end of the method.
+ // Instead, we return after calling the asynchronous method and send `result` in each of the blocks.
+ ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset* asset) {
+ if (asset) {
+ // We have the asset! Retrieve the metadata and send it off.
+ NSDate* date = [asset valueForProperty:ALAssetPropertyDate];
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[date timeIntervalSince1970] * 1000];
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+ } else {
+ // We couldn't find the asset. Send the appropriate error.
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+ }
+ };
+ // TODO(maxw): Consider making this a class variable since it's the same every time.
+ ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError* error) {
+ // Retrieving the asset failed for some reason. Send the appropriate error.
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[error localizedDescription]];
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+ };
+
+ ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
+ [assetsLibrary assetForURL:[NSURL URLWithString:argPath] resultBlock:resultBlock failureBlock:failureBlock];
return;
}
@@ -492,7 +514,6 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
NSFileManager* fileMgr = [[NSFileManager alloc] init];
NSError* __autoreleasing error = nil;
- CDVPluginResult* result = nil;
NSDictionary* fileAttribs = [fileMgr attributesOfItemAtPath:testPath error:&error];