1

如果我在我的数据库中的照片库 (ALAsset) 中保留照片图像的 url 几天,我怎么知道这张照片仍然存在于照片库中的 NSURL?

我已经尝试过了,但没有奏效:

// Have already obtained the asset object from ALAssetsLibrary
NSURL *assetURL = [[(ALAsset*)asset defaultRepresentation] url];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath: [assetURL absoluteString]];
NSLog(@"exists: %d (%@)", exists, [assetURL absoluteString]);

>> exists: 0 (assets-library://asset/asset.PNG?id=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX&ext=PNG)
4

1 回答 1

0

试试这个作为你的要求。核实

dispatch_group_t group = dispatch_group_create();
    dispatch_group_enter(group);
    __block BOOL flag=YES;
    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:path resultBlock:^(ALAsset *asset) {
        if (asset==nil)
        {
            flag=NO;
        }
        else
        {
            flag=YES;
        }
            dispatch_group_leave(group);
        } failureBlock:^(NSError *error){
                NSLog(@"operation was not successfull!");
                dispatch_group_leave(group);
    }];
    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
    dispatch_release(group);
于 2013-09-11T13:16:41.023 回答