【问题标题】:AssetsLibrary not producing failure when expectedAssetsLibrary 未按预期产生故障
【发布时间】:2023-03-09 09:15:01
【问题描述】:

我有这个代码:

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

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

找不到照片 1000000141
成功

如果照片不存在时它不会显示我,我怎么才能知道?

【问题讨论】:

    标签: objective-c ios assetslibrary


    【解决方案1】:

    解决了!

    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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 2019-10-27
      • 2020-03-25
      • 2023-03-24
      • 2017-08-15
      相关资源
      最近更新 更多