无法从相机胶卷获取dateTimeOriginal

时间:2014-06-09 08:58:27

标签: uiimageview uiimagepickercontroller camera-roll

我的应用程序使用didFinishPickingMediaWithInfo 拍摄照片,我想将其保存在相机胶卷

UIImage *orgImage=[[UIImage alloc]init];
    orgImage = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];

    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        UIImageWriteToSavedPhotosAlbum(orgImage, nil, nil, nil);}

我保存完成,但是当我从相机胶卷获取相同的图像时 元数据没有dateTimeOriginal

/ Camera Roll
    if ([info valueForKey:UIImagePickerControllerReferenceURL] != nil)
    {
        NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];

        if(imageURL)
        {

            ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
            [assetslibrary assetForURL:imageURL
                           resultBlock:^(ALAsset *myasset)
             {
                 ALAssetRepresentation *representation = [myasset defaultRepresentation];

                 NSDictionary *metadata = representation.metadata;

                 NSDictionary *exifData = [metadata objectForKey:@"{Exif}"];

                 NSString *dateTimeOriginal = [exifData objectForKey:@"DateTimeOriginal"];

             }
                          failureBlock:^(NSError *myerror)
             {
                 // Error
             }];
        }

    }

1 个答案:

答案 0 :(得分:0)

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

    NSURL *url = [info objectForKey:@"UIImagePickerControllerReferenceURL"];

    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:url
                   resultBlock:^(ALAsset *asset) {
                       NSDate *myDate = [asset valueForProperty:ALAssetPropertyDate];
                       NSLog(@"Date: %@", myDate);
                   } failureBlock:^(NSError *error) {
                       NSLog(@"Error");
                   }];

    [picker dismissViewControllerAnimated:YES completion:nil];

}