Saving Video in an Album Created

前端 未结 1 693
渐次进展
渐次进展 2020-12-30 10:20

i have created an album using this code in AppDelegate methode

NSString *albumName=@\"999Videos\";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];         


        
相关标签:
1条回答
  • 2020-12-30 10:56

    After tearing my hair out over this finally i found the solution.Here is my code.

    NSString *albumName=@"999 Videos";
                    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                    [library addAssetsGroupAlbumWithName:albumName
                                             resultBlock:^(ALAssetsGroup *group) {
                                                 NSLog(@"added album:%@", albumName);
                                                }
                                            failureBlock:^(NSError *error) {
                                                NSLog(@"error adding album");
    
                                            }];
    
    __block ALAssetsGroup* groupToAddTo;
        [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                                        usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                                if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:albumName]) {
                                                        NSLog(@"found album %@", albumName);
                                                        groupToAddTo = group;
                                                    }
                                                }
                                              failureBlock:^(NSError* error) {
                                                  NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
                                              }];
    
    
                    [library assetForURL:assetURL
                                  resultBlock:^(ALAsset *asset) {
                                      // assign the photo to the album
                                      [groupToAddTo addAsset:asset];
                                      NSLog(@"Added %@ to %@", [[asset defaultRepresentation] filename], albumName);
                                  }
                                 failureBlock:^(NSError* error) {
                                     NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
                                 }];
    
    0 讨论(0)
提交回复
热议问题