ALAssetsGroupPropertyName

ALAssetsGroupPropertyName

我正在尝试获取所有专辑的名称。这是我的工作。

方法[group valueForKey:ALAssetsGroupPropertyName]崩溃

ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos | ALAssetsGroupAlbum
                             usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

                                 if (nil != group)
                                 {
                                     NSLog(@"name %@",[group valueForKey:ALAssetsGroupPropertyName]);
                                 }
                                 *stop = NO;
                             } failureBlock:^(NSError *error) {
                                 NSLog(@"error: %@", error);
                             }];

我真的不知道为什么它崩溃,如果有人知道,我将非常感谢您的帮助!

这是崩溃日志:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ALAssetsGroup 0x17801ff90> valueForUndefinedKey:]: this class is not key value coding-compliant for the key ALAssetsGroupPropertyName.`

最佳答案

您正在调用错误的方法。更改此:

NSLog(@"name %@",[group valueForKey:ALAssetsGroupPropertyName]);

至:
NSLog(@"name %@",[group valueForProperty:ALAssetsGroupPropertyName]);

10-06 02:54