views:

1402

answers:

1

Hi guys, I have an application with In-App Purchase, that when the user buy something, download one html file into the Documents folder of my app.

Now I must check if this HTML file exists, so if true, load this HTML file, else load my default html page.

How I can do that? With NSFileManager i can't get outside of mainBundle..

Thanks to everyone can help me!

+4  A: 
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

... gives you the path to the documents directory. The following checks if there's a file named foo.html:

NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
Nikolai Ruhe
Note that you're loading a file out of your application's personal Documents directory, not the global one you find if you're jailbroken.If you install your application in /Applications as if it was a main application you'll have access to the entire file system and you'll use the shared Documents directory. If you install it via iTunes or XCode you'll be using your applications' personal directory.It's nice to store files in your local directory for backup purposes.
Epsilon Prime
Thank you! It works like a charme! :)
Obliviux