First you need to create a folder:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library addAssetsGroupAlbumWithName:folderName
resultBlock:^(ALAssetsGroup *group)
{
NSLog(@"Added folder:%@", folderName);
}
failureBlock:^(NSError *error)
{
NSLog(@"Error adding folder");
}];
Then, find the folder:
__block ALAssetsGroup* folder;
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:folderName])
{
folder = group;
}
}
failureBlock:^(NSError* error)
{
// Error handling.
}];
And add your photo to it.
Save the Image to Asset Library, and put it into the album:
[library writeImageToSavedPhotosAlbum:yourImage
metadata:[info objectForKey:UIImagePickerControllerMediaMetadata]
completionBlock:^(NSURL* assetURL, NSError* error)
{
if (error.code == 0)
{
// Get the asset
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset)
{
// Assign the photo to the album
[folder addAsset:asset];
}
failureBlock:^(NSError* error)
{
// Error handling.
}];
}
else
{
// Error handling.
}
}];