Question

please help me with my question:

Can I give URLs and metadata for all the images/videos in iPhone library with ALAssetsLibrary? Can I edit/delete these images/videos?

Was it helpful?

Solution

Take a look at the documentation for ALAssetsLibrary here. To access all photos and videos you need to enumerate all groups (albums) in the photo library and then enumerate all photos and images in each group. You cannot delete assets using the API. iOS 5 adds extra functionality - it's still under NDA though and cannot be discussed here - have a look at the beta documentation and Apple Developer forums for iOS5.

Your code will need to do something like this:

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];


[al enumerateGroupsWithTypes:ALAssetsGroupAll

    usingBlock:^(ALAssetsGroup *group, BOOL *stop)
    {
        [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
        {
            if (asset)
            {                
                 .. do something with the asset
            }
        }
        ];
    }

    failureBlock:^(NSError *error)
    {
        // User did not allow access to library
        .. handle error 
    }
 ];

OTHER TIPS

the above code has missed some braces so it is resolved below

ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
assets = [[NSMutableArray alloc] init];
[al enumerateGroupsWithTypes:ALAssetsGroupAll

                  usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
      {
          if (asset)
          {  
               NSLog(@"%@",asset);  

              NSLog(@".. do something with the asset");    
          }
      }
      ];
 }

                         failureBlock:^(NSError *error)
      {
          // User did not allow access to library
         // .. handle error 
      }
      ] ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top