在图库中访问暴增模式照片

25

我正在尝试访问用户使用Burst Mode拍摄的iOS资产库中的照片。 我正在使用ALAssetsLibrary并筛选照片:

- (void)findBurstModePhotos
{
    ALAssetsFilter *allPhotos = [ALAssetsFilter allPhotos];

    ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];

    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
                                usingBlock:^(ALAssetsGroup *group,
                                             BOOL *stop) {
                                    [group setAssetsFilter:allPhotos];

                                    NSLog(@"Group: %@",
                                          [group valueForProperty:
                                           ALAssetsGroupPropertyName]);

                                    if ([group numberOfAssets] > 0) {
                                        [self evaluateGroup:group];
                                    }
                                }
                              failureBlock:^(NSError *error) {
                                  NSLog(@"Failure enumerating groups: %@",
                                        [error localizedDescription]);
                              }];
}

- (void)evaluateGroup:(ALAssetsGroup *)group
{
    [group enumerateAssetsUsingBlock:^(ALAsset *result,
                                       NSUInteger index,
                                       BOOL *stop) {
        NSLog(@"Photo date: %@", [result valueForProperty:ALAssetPropertyDate]);
    }];
}

很遗憾,这会把爆发模式(Burst Mode)的照片作为单个照片返回。有没有一种支持的方法可以逐个获取爆发模式照片?我想从一个爆发模式会话中获取每张照片。


这更像是一个问题,当您检查*result的属性ALAssetPropertyType时,它是否报告为ALAssetTypePhoto?我之所以问是因为我想知道是否有新的ALAssetType,他们还没有记录(在API尚未完全实现这些类型的情况下)。 - AndrewPK
这只是5/5S的区别吗?我没有机会保存一个照片吗?似乎我得到了所有的照片作为单独的照片。 - James Webster
你是否查看了ALAssetPropertyURLs的内容以获取可用的连拍收藏? - Wain
@JamesWebster:看起来你是对的。这是5/5s的区别。 - Jeff Kelley
@Wain:我尝试查看ALAssetPropertyURLs的值,但它只返回一个URL,用于在iPhone 5s上拍摄的连拍模式照片。 - Jeff Kelley
显示剩余3条评论
1个回答

1
根据我的理解,连拍模式的照片将一个接一个地添加到库中。每张图片的ALAssetProperty类型将是ALAssetTypePhoto。因此,您可以使用以下ALAsset块单独获取每张照片。由于仅有7种ALAssetsGroupTypes和3种ALAssetsFilters可用,因此您无法一次检索仅限于连拍模式照片的集合。其中没有任何与连拍模式照片相关的内容。我希望Apple将来会提供连拍照片过滤功能。
---------------------------- ALAssetsGroupType -------------------------------------------

ALAssetsGroupLibrary      // The Library group that includes all assets.
ALAssetsGroupAlbum        // All the albums synced from iTunes or created on the device.
ALAssetsGroupEvent        // All the events synced from iTunes.
ALAssetsGroupFaces        // All the faces albums synced from iTunes.
ALAssetsGroupSavedPhotos  // The Saved Photos album.
ALAssetsGroupPhotoStream  // The PhotoStream album.
ALAssetsGroupAll          // The same as ORing together all the available group types,with the exception that ALAssetsGroupLibrary is not included.


-------------------------- ALAssetsFilter ------------------------------------------------

+ (ALAssetsFilter *)allPhotos; // Get all photos assets in the assets group.
+ (ALAssetsFilter *)allVideos; // Get all video assets in the assets group.
+ (ALAssetsFilter *)allAssets; // Get all assets in the group.

使用以下代码单独获取每张照片,包括连拍模式的照片:
- (void)findBurstModePhotos
{
    ALAssetsLibrary *assetLibrary = [ViewController defaultAssetsLibrary];

    [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
    [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

      if(result)
      {
        [self evaluateGroup:group];
      }

    }];

    } failureBlock:^(NSError *error) {
        NSLog(@"Error loading images %@", error);
    }];
}

- (void)evaluateGroup:(ALAssetsGroup *)group
{
    [group enumerateAssetsUsingBlock:^(ALAsset *result,
                                       NSUInteger index,
                                       BOOL *stop) {
        NSLog(@"Photo date: %@", [result valueForProperty:ALAssetPropertyDate]);
    }];
}

+ (ALAssetsLibrary *)defaultAssetsLibrary
{
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library;
}

输出日志:

Photo date: 2013-05-06 15:57:21 +0000 //non burst image.
Photo date: 2013-05-06 15:57:41 +0000 //non burst image.
Photo date: 2013-12-20 21:10:40 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:41 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:42 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:43 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:44 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:45 +0000 //burst image.
Photo date: 2013-12-20 21:10:46 +0000 //burst image.

注意:

如果连拍模式照片捕获相机是您的应用程序的一部分,则在将捕获的照片保存到照片库时,请存储ALAsset URL。您可以通过ALAsset库使用保存的ALAsset URL检索此照片。


你拍这些照片时用的是什么设备?使用类似的代码,我在 iPhone 5s 上只能得到一张照片。 - Jeff Kelley
你把所有的照片都保存到相册里了吗?使用第三方应用程序进行拍摄吗?还是使用默认相机? - Shamsudheen TK
另外,你的代码和我的有点不同。请将你的代码更新为和我一样的,检查结果并回复我。另外,希望你能在设备照片库中看到所有的连拍照片。请确认。 - Shamsudheen TK
1
@Ramshad,所以你的解决方案基本上是检查时间戳,看看这些图像是否在短时间内拍摄?如果这就是我们所拥有的全部 - 那么我真的希望苹果能在不久的将来采取一些措施解决这个问题。 - AndrewPK
@AndrewPK:是的,那就是我们目前拥有的全部 :) - Shamsudheen TK
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接