本文介绍了如何使用URL检查ALAsset是否仍然存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含ALAsset url的数组(不是完整的ALAsset对象)
因此,每次启动我的应用程序时,我都想检查我的数组以查看它是否仍然是最新的...
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...
所以我尝试了
NSData *assetData = [[NSData alloc] initWithContentsOfFile:@"assets-library://asset/asset.PNG?id=1000000001&ext=PNG"];
但是assetData始终为零
but assetData is allways nil
thx寻求帮助
推荐答案
请改用ALAssetsLibrary的assetForURL:resultBlock:failureBlock:方法从其URL获取资产。
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)
}];
这篇关于如何使用URL检查ALAsset是否仍然存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!