получить дату создания из фильма из фотоальбома/UIimagepickercontroller

Как я могу получить дату создания фильма, который я получил через UIimagepickercontroller. Я получил следующий код, но нет информации о дате создания. Я также пробовал атрибуты файла, но не повезло.

NSURL *url = urlfromimagepicker;
NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES };
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:options];

NSArray *metadata = [asset commonMetadata];
for ( AVMetadataItem* item in metadata ) {
    NSString *key = [item commonKey];
    NSString *value = [item stringValue];
    NSLog(@"key = %@, value = %@", key, value);
}

person fellowworldcitizen    schedule 02.11.2012    source источник


Ответы (2)


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if(CFStringCompare((CFStringRef) mediaType,  kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        //Dismiss the media picker view
        [picker dismissModalViewControllerAnimated:YES];

        //Get the URL of the chosen content, then get the data from that URL
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
        NSData *webData = [NSData dataWithContentsOfURL:videoURL];

        //Gets the path for the URL, to allow it to be saved to the camera roll
        NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
        {
            ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];

            //The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
            [lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
                NSLog(@"created: %@", [asset valueForProperty:ALAssetPropertyDate]);
            } failureBlock:^(NSError *error) {
                NSLog(@"error: %@", error);
            }];
        }
    }
}

обратитесь к этому вопросу: Как я могу отслеживать медиафайлов, созданных/выбранных UIImagePickerController?

person sunkehappy    schedule 02.11.2012
comment
Есть ли способ избавиться от этого уродливого предупреждения, запрашивающего разрешения на определение местоположения? Я не получаю доступ к местоположению, только к дате создания. - person fellowworldcitizen; 02.11.2012

ALAsset имеет свойство valueForProperty и содержит:

NSString *const ALAssetPropertyType;
NSString *const ALAssetPropertyLocation;
NSString *const ALAssetPropertyDuration;
NSString *const ALAssetPropertyOrientation;
NSString *const ALAssetPropertyDate;
NSString *const ALAssetPropertyRepresentations;
NSString *const ALAssetPropertyURLs;
NSString *const ALAssetPropertyAssetURL; 

Используйте так:

ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset){
     NSLog(@"created Date: %@",[myAsset valueForProperty:ALAssetPropertyDate]);
};
person Paresh Navadiya    schedule 02.11.2012