从照片库中的iOS

问题描述:

我想从一个电影,我把我的iPhone/iPad上的时间,日期和地点获得ALAssets这是我用从照片库中的iOS

代码//我得到的视频挑选,然后保存它应用程序,但我想我得到电影的资产数据,然后我保存它。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ NSError *error; 
else if (picker.sourceType ==UIImagePickerControllerSourceTypePhotoLibrary) { 

    NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ; 
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init]; 
    [assetslibrary assetForURL:movieURL 
        resultBlock:^(ALAsset*asset) { 
         NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate]; 
         NSLog(@"Date: %@", myDate); 

        } failureBlock:^(NSError *error) { 
         NSLog(@"Error"); 
        }]; 
    NSData * movieData = [NSData dataWithContentsOfURL:movieURL]; 
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0]; 
    NSString *slash = [documentsDirectory stringByAppendingPathComponent:@"/"]; 
    NSString *documentsDirectory2 = [slash stringByAppendingPathComponent:self.user.text]; 
    NSString *documentsDirectory21 = [documentsDirectory2 stringByAppendingPathComponent:@"/Movie"]; 
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory21]) 
     [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory21 withIntermediateDirectories:NO attributes:nil error:&error]; 
    NSString *fullPath = [documentsDirectory21 stringByAppendingPathComponent:[[self imageNameTextField]text]]; 
    fullPath = [fullPath stringByAppendingFormat:@".mp4"]; 
    [ movieData writeToFile:fullPath atomically:YES]; 
} 

然而指明MyDate被记录为空

我在做什么错

我只是尝试这种代码也(加入10/11)

CGImageSourceRef源= CGImageSourceCreateWithURL((CFURLRef) movieURL,NULL);

NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL)); 
    NSLog(@"image data %@", metadata); 

但仍然元数据为空;

我看到视频没有与图像相同的元数据。如果这是真的,那么我如何访问视频元数据,因为我可以看到与照片中的视频相关的数据。

任何帮助,将不胜感激。

我已经尝试了一切,我可以在互联网上找到帮助我这样做,但似乎没有任何工作。 当我登录我movieURL这是我得到

2016-10-13 09:58:51.045271 my little world app[2641:1388034]  movieURL;file:///private/var/mobile/Containers/Data/Application/22A178E5-74C4- 48EF-B487-5E01321508AD/tmp/trim.04F0AC8A-2960-464D-8670-7E79662EAB9B.MOV 

所以,因为它是在一个临时文件,我没有得到的元数据。

元数据是否在电影NSData中退出,我可以从中获得它吗?

我拉我的头发。

所以我想通了这一点这里是代码

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

{ 
if (picker.sourceType ==UIImagePickerControllerSourceTypePhotoLibrary) { 
NSURL * movieURL = [info valueForKey:UIImagePickerControllerMediaURL] ; 
[self getMediaName:nil url:[info objectForKey:UIImagePickerControllerReferenceURL]]; 
} 
} 
- (void)getMediaName:(UIImage*)originalImage url:(NSURL*)url { 
    @try { 
     ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset) { 
      if (asset == nil) return; 
      ALAssetRepresentation *assetRep = [asset defaultRepresentation]; 
      NSString *fileName = [assetRep filename]; 
NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate]; 
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
      [dateFormatter setDateFormat:@"MM-dd-yyyy"]; 
      NSLog(@"%@",[dateFormatter stringFromDate:myDate]); 
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *error) { 

     }; 

     ALAssetsLibrary *library = [ALAssetsLibrary new]; 
     [library assetForURL:url resultBlock:resultblock failureBlock:failureblock]; 
    } 
    @catch (NSException *exception) { 

    } 
} 

你可以使用任何valueForProperty