ios - Objective-C - EXC_BAD_ACCESS error with ALAsset and XmlWriter -
i'm using alassetlibrary
retrieve information images on device (ios simulator) moment. have needed information, want write them xml file
. i'm using xmlstreamwriter
(https://github.com/skjolber/xswi) simple , easy use. problem i'm having exc_bad_access (code=1)
error when run application. know related streamwriter
because if comment lines of code program work perfectly. here there code (i'm using 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 can problem?
i have image related error:
thanks
enumerategroupswithtypes
calls block process found information asynchronously. so, calling [xmlwriter writeenddocument
before have ever written real content writer.
you need change how complete write operation done inside block , when group
passed nil
. add else
block existing check , put
[xmlwriter writeendelement]; [xmlwriter writeenddocument]; nsstring* xml = [xmlwriter tostring]; nslog(@"xml: %@", xml);
in (and whatever subsequently do).
Comments
Post a Comment