Objective-C / ALAssetslibrary - How to Get the Right Asset Path

I implemented a simple method that found the path to images inside the device. I actually use the iPhone Simulator. This is the code 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 write down the path to the images, I get this: "assets-library: //asset/asset.JPG", which for what I know is not the whole path with the exact location of the image. Are you okay? So how can I get all the way to the resource?

thanks

+4
source share
1 answer

You are not correctly extracting the URL from the asset description.

Consider using ALAsset valueForProperty: to make the task easier.

 NSURL *url = [asset valueForProperty:ALAssetPropertyAssetURL]; 

You can later use the URL to retrieve the asset from the library using the ALAssetsLibrary: forForLL attribute:

 [library assetForURL:self.url resultBlock:^(ALAsset *asset) { } failureBlock:^(NSError *error) { }]; 
+1
source

Source: https://habr.com/ru/post/1499394/


All Articles