Search code examples
objective-cioscocos2d-iphone

Embedding XML to iOS application


I'm making my first game in iOS and I need to load some levels that are stored as XML. Level files are stored locally and everything works fine from emulator. However, since XML is loaded in the runtime when i try to test my game on an actual device it can't find the XML files since they are not actually part of the app.

I'm coming from Flash background so I might have a wrong idea how this is done on iOS but I need to somehow bundle those XML files with the app, or embed it in the code somehow? Is this possible?

Thanks a lot :)


Solution

  • Well The code to look up your app bundle for the specified file is

    NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName.xml" ofType:nil]
    NSURL *xmlURL = [NSURL fileURLWithPath:path];
    [[NSXMLParser alloc] initWithContentsOfURL: xmlURL]
    

    Hope this helps you...