【发布时间】:2011-11-18 04:54:54
【问题描述】:
我正在读取 ALAsset 对象的数组(在头文件中标记为 NSMutableArray *assets;)。我正在尝试关注this example,以便将 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,并且正在模拟器上运行。
【问题讨论】:
标签: iphone ios ipad dictionary alassetslibrary