How to check if an ALAsset still exists using a URL

前端 未结 4 911
悲哀的现实
悲哀的现实 2020-12-05 11:57

I\'ve got an array containing ALAsset urls (not full ALAsset objects) So each time I start my application I want to check my array to see if it\'s still up to date...

<
4条回答
  •  死守一世寂寞
    2020-12-05 12:27

    For iOS 8 or later, there is a synchronous method to check if an ALAsset exists.

    @import Photos;
    
    if ([PHAsset fetchAssetsWithALAssetURLs:@[assetURL] options:nil].count) {
        // exist
    }
    

    Swift:

    import Photos
    
    if PHAsset.fetchAssetsWithALAssetURLs([assetURL], options: nil).count > 0 {
       // exist
    }
    

    Swift 3:

    import Photos
    
    if PHAsset.fetchAssets(withALAssetURLs: [assetURL], options: nil).count > 0 {
       // exist
    }
    

提交回复
热议问题