AssetsLibrary在预期时不会产生失败

时间:2011-08-27 14:03:39

标签: objective-c ios assetslibrary

我有这段代码:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:albumCopy
                 resultBlock:^(ALAsset *asset)  {
                     NSLog(@"success");
                     ...
}
            failureBlock:^(NSError *error) {
                    NSLog(@"fail");
                    ...
                }];
        [library autorelease];

问题在于,当我给它一个不存在的图像时,NSLog会出现:

  

找不到照片1000000141
  成功

如果在照片不存在时不会显示,我怎么才能找到?

1 个答案:

答案 0 :(得分:2)

解决了!

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
        [library assetForURL:albumCopy
                 resultBlock:^(ALAsset *asset)  {
                     if (asset == nil) {
                         //Image not in photo library
                     }
                     else {
                     //Image in photo library
                     }
                 }
                failureBlock:^(NSError *error) {
                    //Error
                }];
        [library autorelease];