访问库中的Burst Mode照片

时间:2013-12-10 02:52:39

标签: ios alassetslibrary alasset alassetsgroup

我正在尝试使用突发模式访问用户已使用的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照片作为单张照片返回。是否有支持的方式单独获取Burst Mode照片?我想从单个突发模式会话中获取每张照片。

1 个答案:

答案 0 :(得分:1)

根据我的理解,Burst Mode照片将逐个添加到库中。每张图片的ALAssetProperty类型将为ALAssetTypePhoto。因此您可以使用以下内容分别获取每张照片ALAsset块。您不能一次只检索一组Burst Mode照片,因为ALAssetsGroupTypes只有7种类型,ALAssetsFilters有3种可用。他们都没有处理Burst Mode照片。

我希望Apple将来会提供Burst照片过滤功能。

---------------------------- 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's。您可以使用保存的ALAsset URL's来恢复此照片ALAsset图书馆。