我正在读取 ALAsset 对象的数组(NSMutableArray *assets;
在头文件中删除)。我正在尝试按照此示例将 ALAssets 字典的内容打印到文件以供稍后检索。请注意,我可以正确地将字典键写入文件(已注释掉),但不能正确写入值。
这是我在 viewDidLoad() 方法末尾运行的代码:
// Create path to Documents
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) {
NSString *dictPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"dict.out"];
NSDictionary *aDict = [[assets objectAtIndex:0] valueForProperty:ALAssetPropertyURLs];
for (id key in aDict) {
NSLog(@"key: %@, value: %@", key, [aDict valueForKey:key]);
//[key writeToFile:dictPath atomically:YES]; <- THIS LINE WORKS
[[aDict valueForKey:key] writeToFile:dictPath atomically:YES];
}
}
else
NSLog(@"nope"); // The program doesn't get here.
日志如下所示:
2011-11-17 23:44:41.340 PhotoApp[542:12803] 键:public.jpeg,值:asset-library://asset/asset.JPG?id=1000000001&ext=JPG
2011-11-17 23:44:41.361 PhotoApp[542:12803]-[NSURL writeToFile:atomically:]: 无法识别的选择器发送到实例 0x6455650
2011-11-17 23:44:41.370 PhotoApp[542:12803] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSURL writeToFile:atomically:]:无法识别的选择器发送到实例 0x6455650”
编辑:不确定是否重要,但该项目是针对 iPad 的,并且正在模拟器上运行。