[英]Objective-C - EXC_BAD_ACCESS error with ALAsset and XmlWriter
I'm using the ALAssetLibrary
to retrieve information about the images on the device (IOS Simulator) for the moment. 我目前正在使用ALAssetLibrary
来检索有关设备(IOS Simulator)上图像的信息。 Now that I have the needed information, I want to write them like an xml file
. 现在,我已经有了所需的信息,我想像xml file
一样编写它们。 To do this I'm using the XmlStreamWriter
( https://github.com/skjolber/xswi ) simple and easy to use. 为此,我使用了简单易用的XmlStreamWriter
( https://github.com/skjolber/xswi )。 My problem is that I'm having a EXC_BAD_ACCESS (code=1)
error when I run the application. 我的问题是,运行应用程序时出现EXC_BAD_ACCESS (code=1)
错误。 I know that it is related to the streamWriter
because if I comment this lines of code the program work perfectly. 我知道它与streamWriter
有关,因为如果我注释这行代码,则该程序可以完美运行。 Here there is my code (I'm using ARC
): 这是我的代码(我正在使用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);
Any idea of what can be the problem? 知道可能是什么问题吗?
I also have an image with the related error: 我也有一个带有相关错误的图像:
Thanks 谢谢
enumerateGroupsWithTypes
calls the block to process the found information asynchronously. enumerateGroupsWithTypes
调用该块以异步处理找到的信息。 So, you are calling [xmlWriter writeEndDocument
before you have ever actually written any real content into the writer. 因此,在实际将任何实际内容写入写入[xmlWriter writeEndDocument
之前,您要调用[xmlWriter writeEndDocument
。
You need to change how you complete the write operation so that it is done inside the block and when group
is passed as nil
. 您需要更改完成写操作的方式,以使其在块内以及group
作为nil
传递时完成。 Add an else
block to your existing check and put 在您现有的支票上添加一个else
块并放入
[xmlWriter writeEndElement];
[xmlWriter writeEndDocument];
NSString* xml = [xmlWriter toString];
NSLog(@"XML: %@", xml);
In it (and whatever you subsequently do). 在其中(以及随后执行的任何操作)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.