我目前正在使用ALAssetLibrary
检索有关设备(IOS 模拟器)上图像的信息。现在我有了所需的信息,我想把它们写成xml file
. 为此,我使用了XmlStreamWriter
( https://github.com/skjolber/xswi ) 简单易用。我的问题是EXC_BAD_ACCESS (code=1)
运行应用程序时出现错误。我知道它与 相关,streamWriter
因为如果我评论这行代码,程序可以完美运行。这是我的代码(我正在使用ARC
):
XMLWriter* xmlWriter = [[XMLWriter alloc]init];
[xmlWriter writeStartDocumentWithEncodingAndVersion:@"UTF-8" version:@"1.0"];
[xmlWriter writeStartElement:@"Photos"];
NSMutableArray *list = [[NSMutableArray alloc] init];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (group) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if (asset){
[xmlWriter writeStartElement:@"Photos"];
NSString *description = [asset description];
NSRange first = [description rangeOfString:@"URLs:"];
NSRange second = [description rangeOfString:@"?id="];
NSString *path = [description substringWithRange: NSMakeRange(first.location + first.length, second.location - (first.location + first.length))];
[xmlWriter writeAttribute:@"id" value:path];
[xmlWriter writeEndElement:@"Photos"];
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
[xmlWriter writeEndElement];
[xmlWriter writeEndDocument];
NSString* xml = [xmlWriter toString];
NSLog(@"XML: %@", xml);
知道可能是什么问题吗?
我还有一张带有相关错误的图片:
谢谢