25

I’m trying to access photos in the iOS asset library that the user has taken using Burst Mode. I’m trying using ALAssetsLibrary and filtering photos:

- (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]);
    }];
}

Unfortunately, this returns Burst Mode photos as a single photo. Is there a supported way to get Burst Mode photos individually? I’d like to get each photo from a single Burst Mode session.

Jeff Kelley
  • 18,594
  • 5
  • 67
  • 80
  • You might have already verified this but I hope you have not deleted all other versions of photos except the favorite one in burst mode. – TorukMakto Dec 10 '13 at 04:54
  • Good guess, but I have not deleted the other versions of the photo. – Jeff Kelley Dec 10 '13 at 05:49
  • This is more of a question than anything - but when you inspect the *result's property `ALAssetPropertyType` is it reporting as `ALAssetTypePhoto`? I ask because I wonder if there's a new ALAssetType that they just don't have documented yet (in the unexpected case that the API to utilize these types has not fully been implemented yet). – AndrewPK Dec 10 '13 at 16:12
  • Yep, all photos. I tried removing the `ALAssetsFilter` and looking for all types, but no luck. – Jeff Kelley Dec 10 '13 at 16:39
  • Is it just an 5 / 5S difference that I don't get the chance to save just one? It seems I get all photos as separate photos. – James Webster Dec 16 '13 at 17:23
  • Have you looked at the contents of `ALAssetPropertyURLs` for the available burst favourite? – Wain Dec 17 '13 at 16:06
  • @JamesWebster: It looks like you’re right. It’s the 5/5s difference. – Jeff Kelley Dec 28 '13 at 01:56
  • @Wain: I tried looking at the value for `ALAssetPropertyURLs`, but it returns one URL for Burst Mode photos taken on an iPhone 5s. – Jeff Kelley Dec 28 '13 at 02:08

1 Answers1

1

From my understandings, the Burst Mode photos will be added to the library as one by one.The ALAssetProperty type of each image will be ALAssetTypePhoto.So you can get each photo separately using the below ALAsset block. You can't retrieve only the set of Burst Mode photos at a time because there are only 7 types of ALAssetsGroupTypes and 3 kinds of ALAssetsFilters are available. None of them are dealing with Burst Mode photos.

I hope Apple will provide Burst photo filtering in the future.

---------------------------- 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.

Use the below code to get each photo separately including the Burst Mode photos,

- (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;
}

Output Log:

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.

Note:

If the Burst Mode photo capture camera is a part of your application,then store the ALAsset URL's when saving the captured photos to the photo gallery.You can retrieve this photo back using the saved ALAsset URL's via ALAsset library.

Shamsudheen TK
  • 28,767
  • 9
  • 64
  • 96
  • What device were you using when you took those photos? Using similar code I’m only getting one photo back on an iPhone 5s. – Jeff Kelley Dec 22 '13 at 02:40
  • did you save all the pics into photo-gallery? using any 3rd party app to capture it? or using the default camera? – Shamsudheen TK Dec 22 '13 at 02:43
  • Also your code is little differ than mine.Update your code as mine , check the results and get back to me. Also I hope that you can see all the Burst mode pics in your device photos gallery.Please confirm. – Shamsudheen TK Dec 22 '13 at 02:46
  • This is essentially the same as my answer but with a less complete solution. – James Webster Dec 22 '13 at 19:25
  • From my testing, it looks like iPhone 5s devices do a different Burst Mode, so that explains the difference in our results. Thanks for your help, but the above code will not work on a 5s. – Jeff Kelley Dec 28 '13 at 02:01
  • 1
    @Ramshad So your solution is basically to check timestamps to see if the images were taken closely together? If that's all we have - then I really do hope apple does something about this in the near future. – AndrewPK Jan 12 '14 at 17:08
  • @AndrewPK: Yeah.that's all we have presently:) – Shamsudheen TK Jan 12 '14 at 22:19