簡體   English   中英

檢查PHFsetResult中是否存在PHAsset

[英]Check if PHAsset exists in PHFetchResult

如何知道是否找不到用於本地標識符的資產。 我有從照片框架獲取的每張照片和視頻的localID列表,如何知道照片是否存在於iOS相冊中。

您需要跟蹤該用戶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
        }
}];

為什么不使用:

if ([userAlbums count]) {
    //At least one item found.
}
else {
    //Nothing found
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM