Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-02-2011, 06:09 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 346
mashercakes is on a distinguished road
Default ALAssetsGroup intermittently not editable

I often need to add large numbers of images to many different albums within the simulator for the purpose of recording screen captures of my app (which makes heavy use of images in albums). Dragging and dropping into the simulator and individually saving to albums is far too time consuming, so I'm writing an iOS app to do it automatically. Basically, it does the following:

1. Scans a specified directory for all subdirectories
2. For each subdirectory:
a. Scan for all images in the subdirectory
b. Make an album with the same name as the subdirectory (if needed)
c. Add the image to the camera roll
d. Add the new asset to the album


The problem I am having is that although all images are always added to the camera roll, not all of them get added to the album. I've put some checks in and it seems that the ALAssetsGroup is intermittently going non-editable. Here's a sample of code:

Code:
    ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
    
    //search all photo albums in the library
    [assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAlbum 
                        usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                            
                            //compare the names of the albums
                            if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
                                
                                //target album is found
                                albumWasFound = YES;
                                
                                //get a hold of the photo's asset instance
                                [assetsLibrary assetForURL: assetURL 
                                      resultBlock:^(ALAsset *asset) {
                                          if (![group isEditable]) {
                                              NSLog(@"%@ not editable", albumName);
                                          }
                                          
                                          [group addAsset:asset];
                                          completionBlock(nil);
                                          
                                      } failureBlock: completionBlock];
                                
                                //album was found, bail out of the method
                                return;
                            }

                            // ...


That code is called from a loop which looks like this:

Code:
- (void)processImage {       
    //If there are no images left...
    if ( ![self prImages] || ![[self prImages] count] ) {
        //Tell the user we're done
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"All done" message:@"The images have been imported" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
        
        return;
    }
    
    //Show progress
    NSLog(@"Next image (%d left)", [[self prImages] count]);
    
    //Get image data and destination album name
    UIImage *image = [[[[self prImages] objectAtIndex:0] prImage] copy];
    NSString *album = [[[[self prImages] objectAtIndex:0] prAlbum] copy];
    NSString *path = [[[[self prImages] objectAtIndex:0] prPath] copy];
    
    //Write the image to the album
    [self saveImage:image atPath:path toAlbum:album withCompletionBlock:^(NSError *error) {        
        if (error!=nil) {
            //Something went wrong writing the image
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
            
            [album release];
            [image release];
            [path release];
        }
        
        else {
            //Image should be written by now...
            NSLog(@"Image done");
            
            [album release];
            [image release];
            [path release];
            
            //Remove the image from the list
            [[self prImages] removeObjectAtIndex:0];
            
            //Start processing the next image
            [self processImage];
        }
    }];
}
In the log I can see messages like this:

Quote:
Next image (110 left)
Image done
Next image (109 left)
Image done
but also messages telling me that albums are not editable. The albums all have some pictures in them, so the editable state is changing during the process so some of the images don't get written. It's always different images which fail, so I don't think it's the files.

Sorry for the long post. Any ideas what I'm doing wrong?
__________________
PicBoard - a visual support app for children with autism, communication difficulties or learning difficulties. Available now for iPad.

TalkBoard - Adds Communication Aid features to PicBoard, for non-verbal children or adults. Available now for iPad.
mashercakes is offline   Reply With Quote
Old 03-14-2012, 07:58 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 1
drewconner is on a distinguished road
Default

I'm now running into the same problem. Did you ever find a solution?
drewconner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 391
15 members and 376 guests
AppsBlogger, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, heshiming, iekei, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,913
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0