我正在编写一个小型 iPhone 应用程序来检索存储在 iPhone 中的所有照片的元数据,例如 EXIF 信息,并在调用 Assets Library Framework API 时遇到了一个奇怪的问题。基本上,如果我调用 ALAssetRepresentation 的元数据方法(http://developer.apple.com/library/ios/documentation/AssetsLibrary/Reference/ALAssetRepresentation_Class/Reference/Reference.html#//apple_ref/occ/instm/ALAssetRepresentation/metadata)数百次(即使对于同一个 ALAssetReprsentation 对象),API 将报告错误并返回 null 而不是照片的元数据。
这是重现此问题的代码:
ALAsset *photo = ... // fetch a photo asset via Assets Library Framework
int i = 0;
ALAssetRepresentation *representation = [photo defaultRepresentation];
NSDictionary *metadata;
while (i<600) {
i++;
metadata = [representation metadata];
NSLog(@"photo %d indexed %@", i, metadata);
}
这是上面代码的输出。开始输出时一切正常,但在 500+ 次之后,元数据 API 会报“ImageIO: CGImageSourceCreateWithData data parameter is nil”之类的错误。
...
2011-12-29 21:46:17.106 MyApp[685:707] photo 578 indexed {
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
...
}
...
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
2011-12-29 21:46:17.151 MyApp[685:707] photo 579 indexed (null)
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
2011-12-29 21:46:17.177 MyApp[685:707] photo 580 indexed (null)
我正在使用 iOS 5.0.1 的 iPhone 3GS 中进行测试。我正在使用启用了 ARC(自动引用计数)的 Xcode 4.2 进行开发。而且我只能在将应用程序部署到iPhone 3GS设备时重现此问题,但在使用具有相同代码的iOS模拟器时无法重现此问题(至少我在iOS模拟器中调用API超过1800次后不会重现此问题)。
任何帮助表示赞赏。谢谢。