How to check if an ALAsset still exists using a URL

前端 未结 4 909
悲哀的现实
悲哀的现实 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:22

    Use assetForURL:resultBlock:failureBlock: method of ALAssetsLibrary instead to get the asset from its URL.

    // Create assets library
    ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
    
    // Try to load asset at mediaURL
    [library assetForURL:mediaURL resultBlock:^(ALAsset *asset) {
        // If asset exists
        if (asset) {
            // Type your code here for successful
        } else {
            // Type your code here for not existing asset
        }
    } failureBlock:^(NSError *error) {
        // Type your code here for failure (when user doesn't allow location in your app)
    }];
    

提交回复
热议问题