I am trying to save photos from a app ,create the album and save the photos to it, but it don't works properly.
Sometime it save one or another photo, but never all of them.
Best regards to everyone and thanks!
for(PFObject *pf in imageFilesArray)
{
PFObject *imageObject = pf;
PFFile *imageFile = [imageObject objectForKey:@"image"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:data];
[self.library writeImageToSavedPhotosAlbum:[image CGImage] orientation:ALAssetOrientationUp completionBlock:^(NSURL *assetURL, NSError *error) {
if(assetURL) {
[self.library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
[self addAsset:asset toGroup:@"App Album" inLib:self.library];
NSLog(@"Adicionado");
} failureBlock:^(NSError *error) {
NSLog(@"%@",error);
}];
}
}];
}
}];
}
[hud hide:NO];
The - (void) addAsset:(ALAsset*)a toGroup:(NSString*)name inLib:(ALAssetsLibrary*)lib method
[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);
}];