简体   繁体   中英

Create custom Photo folder in device photos application

I am using the following code for add folder in (Device application)photos application. In block of enumerateGroupsWithTypes if and else condition both running on same time when folder is available.Please tell me why this happen.

[self.library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:Albumname])
     {
         NSLog(@"found album %@", Albumname);

         return ;
     }
     else
     {
         [self.library addAssetsGroupAlbumWithName:Albumname resultBlock:^(ALAssetsGroup *group)
          {
              NSLog(@"added album:%@", Albumname);
          }
            failureBlock:^(NSError *error)
          {
              NSLog(@"error adding album");
          }];
     }
 }
     failureBlock:^(NSError* error)
 {
     NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
 }];

enumerateGroupsWithTypes goes over all of the available groups and runs your block on each of them. Or, according to Apple's documentation:

Invokes a given block passing as a parameter each of the asset groups that match the given asset group type.

The reason both the if and else clauses are executed when the album exists, is that the block is executed for all of the albums. When it reaches your album, it executes the if clause. For all of the others, it executes the else clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM