Question

I am trying to read the contents of an Asset URL directly without writing to the sandbox first. If i write to the sandbox I can read the contents using

 NSFileHandle *readFile = [NSFileHandle fileHandleForReadingFromURL:file error:nil];

but i am unable read an Asset URL using the same method. Although that is the right behavior as i think NSFileHandle is meant for items which are present in the user's sandbox. I was wondering if there is a way to do read from the Asset URL.

No correct solution

OTHER TIPS

ALAsset URLs are not file URLs, so the proper way to read them is

ALAssetsLibrary *lib = [ALAssetsLibrary new];
[lib assetForURL:myAssetURL resultBlock:^(ALAsset *asset) {
   /* Example use. Check out the docs on ALAsset for more:
    UIImage *exampleImage = [UIImage imageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
   */
} failureBlock:^(NSError *error) {
    NSLog(@"Failed to get asset at %@: %@",myAssetURL, error);
}];

Important: Make sure you keep the ALAssetsLibrary alive while you use the ALAsset

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top