如何知道是否找不到本地标识符的资产。我有从照片框架中提取的每张照片和视频的localID列表,如何知道iOS相册中是否存在照片。
答案 0 :(得分:3)
您需要跟踪userAlbums
中的资产数量,如果在检查完最后一项资产之前未找到资产,请返回“未找到”通知。
你可以这样做:
NSString *localId = /*local identifier of photo */;
PHFetchResult *userAlbums = [PHAsset fetchAssetsWithLocalIdentifiers:@[localId] options:nil];
NSUInteger assetCount = [userAlbums count];
__block NSUInteger assetCounter = 0;
[userAlbums enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop)
{
// Check whether you found the asset or not
if (/*asset found*/)
{
// Asset found, set the stop bool to yes
}
else if (assetCounter == assetCount)
{
//Data not found yet
}
}];
答案 1 :(得分:1)
为什么不使用:
if ([userAlbums count]) {
//At least one item found.
}
else {
//Nothing found
}