如何在iOS上获取最近拍摄的图像的路径?

时间:2015-02-20 03:35:10

标签: ios xcode path camera uiimage

在Tweetbot等应用中,有一个"选择最近的图片"功能。我想知道相机胶卷中最近图像的路径是什么。

我知道当我手动从相机胶卷中拾取图像时,检索所述图像的代码如下所示:

UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];

我不知道的是在最新图片的信息valueForKey中放入什么。我广泛搜索并发现了虚无...我知道规则 - 我应该展示我尝试过的东西,但我不知道该尝试什么,因为我在研究中发现zilch并且不熟悉与文件路径相关的编程。

我读了docs并没有发现任何用处。谢谢!

1 个答案:

答案 0 :(得分:0)

在此示例中,最近的照片存储在名为latestPhoto的UIImage中。希望这有帮助!

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group setAssetsFilter:[ALAssetsFilter allPhotos]];
     [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
      {
          if (alAsset)
          {
              ALAssetRepresentation *representation = [alAsset defaultRepresentation];
              UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
          }
      }];
 }
 failureBlock: ^(NSError *error)
 {
     // an error has occurred
 }];