please help me with my qu开发者_如何学编程estion:
Can I give URLs and metadata for all the images/videos in iPhone library with ALAssetsLibrary? Can I edit/delete these images/videos?
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
}
] ;
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
}
];
精彩评论