Home > DeveloperSection > Forums > Checking asset existance of ALAasset in iOS.
Jayden Bell
Jayden Bell

Total Post:105

Points:739
Posted on    January-14-2016 4:53 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 272  View(s)
Rate this:

I have an array of urls that contains ALAsset urls. I want to check existance of any specific url.
I tried this code:

NSData *assets = [[NSData alloc] initWithContentsOfFile:@"asset-library://asset/asset.PNG?id=0X32031&ext=JPG"];

but the nsdata variable assets is always nil. So, how can I solve this problem?



Tarun Kumar

Total Post:213

Points:1635
Supported
Posted on    January-14-2016 11:04 PM

Here I am providing the code, which helps you to check existance of any specific url.
this is the code:

ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:imageUrl resultBlock:^(ALAsset *asset){
 if(asset){
    NSLog(@"Image Exists");
    ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
    UIImage *urlImage = [UIImage imageWithCGImage:[assetRepresentation fullResolutionImage]];
 } else {
    NSLog(@"Image Does't Exist");
 }
} failureBlock:^(NSError *error) {
 NSLog(@"Failure");
});

Don't want to miss updates? Please click the below button!

Follow MindStick