How do I determine if a PHAsset in a PHFetchResult represents a deleted photo?

前端 未结 3 1107
长情又很酷
长情又很酷 2020-12-29 11:14

I\'m trying to grab a thumbnail of the last photo taken on a device using the new Photos framework in iOS 8. The code I have right now to do this is the following:


        
相关标签:
3条回答
  • 2020-12-29 11:59
    PHFetchResult *fetchResults = [PHAsset fetchAssetsWithOptions:options];
    NSArray* tempArray = [fetchResults objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, fetchResults.count)]];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"description contains %@",@"assetSource=3"];
    NSArray *filteredArray =  [tempArray filteredArrayUsingPredicate:predicate];
    

    The filteredArray doesn't include the "Recently Deleted" album and doesn't have identical looking photos. Also for the deleted photo asset in your assetsInfo, the following two will return NO.

    [asset canPerformEditOperation:PHAssetEditOperationContent] 
    [asset canPerformEditOperation:PHAssetEditOperationProperties]
    

    In PHAsset Runtime Headers there are useful properties:

    @property (getter=isTrashed, nonatomic, readonly) bool trashed;
    @property (nonatomic, readonly) NSDate *trashedDate;
    
    0 讨论(0)
  • 2020-12-29 12:01
    PHFetchResult * recentlyDeletedAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:1000000201 options:nil];
    

    This returns collection of all recently deleted assets. You can iterate and get PHAsset for all objects in this collection to check if your PHAsset was deleted or not.

    0 讨论(0)
  • 2020-12-29 12:04

    There is no property indicating if the phasset is deleted or not
    the only way it worked for me is to check again with the PHAssetLocalID

    if PHAsset.fetchAssets(withLocalIdentifiers: [pHAsset.localIdentifier], options: .none).count == 0 { }

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题