views:

98

answers:

1

I want to load content into my application from a web server, but if the internet is not available, I would like the user to have access to either default or old, downloaded content. It will be XML formatted. I know how to download XML from the web server into my app and I can store the XML-as-string and reload. But, how do I "ship" the product with a default XML data file? I tried to create a new resource with add-to-project, but I cannot find the file in my application's directory.

Is this possible?

Ok, I am back on this task. I have my XML properly download from my webserver with a URL pointing to the server's file, however, when I detect the network is 'unreachable' I simply point the URL to my application's local XML and I get the following error. I cannot find detail description, but I think it is saying that the URL is pointing to an inaccessible location. Am I storing this resource in the wrong location? I think I want it in the HomeDirectory / Library??

Debug output

loadMyXml: /var/mobile/Applications/950569B0-6113-48FC-A184-4F1B67A0510F/MyApp.app/SampleHtml.xml

2009-10-14 22:08:17.257 MyApp[288:207] Wah! It didn't work. Error Domain=NSXMLParserErrorDomain Code=5 "Operation could not be completed. (NSXMLParserErrorDomain error 5.)" 2009-10-14 22:08:17.270 MyApp[288:207] Operation could not be completed. (NSXMLParserErrorDomain error 5.)

+1  A: 

Totally! Just include it into your project and make sure it's included in the "Copy Bundle Resources" phase. Then it will be copied into ./YourApp.app/Contents/Resources/. This will work on both Mac and iPhone.

You can easily retrieve it by doing something like this (assuming your file is named "MyXMLFile.plist"):

NSString * pathToMyXMLFile = [[NSBundle mainBundle] pathForResource:@"MyXMLFile" ofType:@"plist"];
Dave DeLong
Fantastic. That worked! I added the following logging and the result is the file attributes showed the correct filesize of 210 bytes. Now I can write my access code. I owe you one ... NSString * pathToMyXMLFile = [[NSBundle mainBundle] pathForResource:@"SampleHtml" ofType:@"xml"]; NSError *errorFile = [[NSError alloc] init]; NSDictionary *attrs; attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:pathToMyXMLFile error: NSLog(@"%@\n:\n%@", pathToMyXMLFile, attrs );
mobibob