ALAssetsGroup,如何检查是否存在?

时间:2021-12-04 00:03:52

I have my ALAssetsGroup object. For example:

我有我的ALAssetsGroup对象。例如:

ALAssetsGroup *_someGroup.

But user can send the application to background and delete this album.

但是用户可以将应用程序发送到后台并删除此相册。

Is there any check if assetsGroup is proper?

如果assetsGroup是正确的,有没有检查?

[_someGroup numberOfAssets] returns the *old number of photos* even when the group doesn't exist

[_someGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)

CRASHES::

崩溃::

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSOrderedSetM getObjects:range:]: range {0, 1} extends beyond bounds for empty ordered set'

*由于未捕获的异常'NSRangeException'终止应用程序,原因:'* - [__ NSOrderedSetM getObjects:range:]:范围{0,1}超出了空有序集的边界'


ALAssetsGroup has also valueForProperty: method, where i can get ALAssetsGroupPropertyURL (Key to retrieve a URL that uniquely identifies the group). So i can enumerate all albums and check if some album with the same property exists. But it is available only in iOS 5.

ALAssetsGroup还有valueForProperty:方法,我可以获取ALAssetsGroupPropertyURL(用于检索唯一标识组的URL的键)。所以我可以枚举所有专辑,并检查是否存在具有相同属性的专辑。但它仅在iOS 5中可用。

1 个解决方案

#1


1  

I found the solution: ALAssetsGroupPropertyPersistentID property works as I expected.

我找到了解决方案:ALAssetsGroupPropertyPersistentID属性按预期工作。

So I can enumerate through the albums and check if they have the same ID.

所以我可以通过相册进行枚举,并检查它们是否具有相同的ID。

#1


1  

I found the solution: ALAssetsGroupPropertyPersistentID property works as I expected.

我找到了解决方案:ALAssetsGroupPropertyPersistentID属性按预期工作。

So I can enumerate through the albums and check if they have the same ID.

所以我可以通过相册进行枚举,并检查它们是否具有相同的ID。