Reputation: 595
I have implemented a simple method that find the path of the images inside the device. Actually i'm using the iPhone Simulator. This is the code that i'm using:
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if (asset){
NSString *description = [asset description];
NSRange first = [description rangeOfString:@"URLs:"];
NSRange second = [description rangeOfString:@"?id="];
NSString *path = [description substringWithRange: NSMakeRange(first.location + first.length, second.location - (first.location + first.length))];
[idList addObject:path];
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}
];
});
At this point, if i log the path of the images i'm receiving this: "assets-library://asset/asset.JPG", that for what i know isn't the entire path with the exactly position of the image. Are you ok? So, how can i obtain the entire path of the asset?
Thanks
Upvotes: 4
Views: 2204
Reputation: 634
You are not retrieving the URL properly from the asset description.
Consider using ALAsset valueForProperty: to ease your task.
NSURL *url = [asset valueForProperty:ALAssetPropertyAssetURL];
You can later use the url to retrieve the asset from the library by using ALAssetsLibrary assetForURL:
[library assetForURL:self.url resultBlock:^(ALAsset *asset) {
} failureBlock:^(NSError *error) {
}];
Upvotes: 1