Pergunta

I have a problem of getting NSData via [NSData dataWithContentsOfURL: url] and giving me an null object where the url is the NSURL got it from defaultRepresentation of the asset.. The url in the NSURL is :

assets-library://asset/asset.JPG?id=1000000366&ext=JPG

I went to other forum, they talked about something like file url... Do I have to convert the url to file path ?

But i can have the thumbnail of the ALAsset on a view.

Does anyone know why i get null NSData object?

Foi útil?

Solução

from what I know these URLs are just for identification or so - you cannot actually access them.

maybe this helps ? ALAsset , send a photo to a web service including its exif data

Outras dicas

If what you're after is the image, you could do something like this...

ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
NSURL *yourAssetUrl = ;//Insert Your ALAsset's URL here
[library assetForURL:yourAssetUrl resultBlock:^(ALAsset *asset) {
    if (asset) {
        ALAssetRepresentation *imgRepresentation = [asset defaultRepresentation];
        CGImageRef imgRef = [imgRepresentation fullScreenImage];
        UIImage *img = [UIImage imageWithCGImage:imgRef];
        CGImageRelease(imgRef);
        [self doSomethingWithImage:img];
    } 
} failureBlock:^(NSError *error) {
}];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top