Determine whether there is a photo album

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sinat_30657013/article/details/51791171

Determine whether there is a photo album

        Now experiencing an extreme problem, App has a function to select pictures, allow multiple choice, multiple choice later, back to the desktop, open the photo album system will delete selected, and then click to use App returned, this time because the picture is deleted abnormal flash back may occur. the following methods can be performed before use to determine whether there is a picture

// photoUrl 是相册图片的链接 ALAssetsLibrary 最好是写一个单例 确保每个地方取到的是同一个
//ALAsset 是照片对象
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
 NSString *url=[[ALAsset valueForProperty:ALAssetPropertyAssetURL] absoluteString];
    [assetLibrary assetForURL:photoUrl resultBlock:^(ALAsset *asset) // substitute YOURURL with your url of video
     {
         ALAssetRepresentation *rep = [asset defaultRepresentation];
         Byte *buffer = (Byte*)malloc(rep.size);
         NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
         NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
         NSLog(@“photo data length  %d",data.length);
         if (data.length == 0)
         {
         NSLog(@"照片不存在");
         }
     }
                 failureBlock:^(NSError *err) {
                     NSLog(@"Error: %@",[err localizedDescription]);
                 }];

Guess you like

Origin blog.csdn.net/sinat_30657013/article/details/51791171