Creating Image Folders in iOS

All,

When a user of my application takes a picture, it will be saved, but I want it to be saved in a new folder called "Jasons Photos", and not in the regular Camera Roll album.

I know the completion block, called save image:imagetoAlbum 'Jasons Album', with completion block, but I get the error " No visible @interface for AlAssetslibrary declares the selector 'save image to album completion block'and it crashes crazy.

I created @property for the ALAssets libraryand I included <AssetsLibrary>in my project.

thank

+4
source share
1 answer

First you need to write it to savePhotos, then get ALAsset and add it to the new group

#import "QBViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>

@implementation QBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
    [lib writeImageToSavedPhotosAlbum:[[UIImage imageNamed:@"polter"] CGImage] orientation:ALAssetOrientationUp completionBlock:^(NSURL *assetURL, NSError *error) {
        if(assetURL) {
            [lib assetForURL:assetURL resultBlock:^(ALAsset *asset) {
                [self addAsset:asset toGroup:@"forest" inLib:lib];
            } failureBlock:^(NSError *error) {
                NSLog(@"e: %@", error);
            }];
        }
        else {
            NSLog(@"e: %@", error);
        }
    }];
}

- (void) addAsset:(ALAsset*)a toGroup:(NSString*)name inLib:(ALAssetsLibrary*)lib {
    [lib enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:name]) {
            [group addAsset:a];
            *stop = YES;
            NSLog(@"added asset to EXISTING group");
        }
        if(!group) {
            [lib addAssetsGroupAlbumWithName:name resultBlock:^(ALAssetsGroup *group) {
                [group addAsset:a];
                NSLog(@"added asset to NEW group");
            } failureBlock:^(NSError *error) {
                NSLog(@"e: %@", error);
            }];
        }
    } failureBlock:^(NSError *error) {
        NSLog(@"e: %@", error);
    }];
}

@end
+4
source

All Articles