我正在使用ALAssetLibrary
來檢索設備(IOS模擬器)上的圖像信息。 現在我有了所需的信息,我想寫他們像xml file
。爲此,我使用簡單易用的XmlStreamWriter
(https://github.com/skjolber/xswi)。我的問題是,當我運行應用程序時,出現EXC_BAD_ACCESS (code=1)
錯誤。我知道它與streamWriter
有關,因爲如果我評論這段代碼,該程序完美工作。 在這裏有我的代碼(我使用ARC
):Objective-C - 使用ALAsset和XmlWriter的EXC_BAD_ACCESS錯誤
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);
什麼可以是問題的任何想法?
我也有相關的錯誤的圖像:
感謝
什麼是異常的堆棧跟蹤?從例外打印的任何日誌? – Wain