0

I am trying to make a simple application (using theos on my device so no xcode/mac, just ifile) that displays an HTML file and has a button in the navigation bar that updates the local HTML file by downloading the new version from a server and overwriting the existing one. My problem is that the newer version of the HTML file does not get downloaded and the existing one remains the same.

When the button is pressed, this is the code that I have to try and update the local HTML file:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"blank" ofType:@"html"]isDirectory:NO]]];

NSData *theData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://mydomain.com/index.html"]];
[theData writeToFile:[NSBundle pathForResource:@"index" ofType:@"html" inDirectory:[[NSBundle mainBundle] bundlePath]] atomically:NO];

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

The blank.html is a blank HTML file. I put it in there so I could sort of refresh index.html and also have index.html not in use white it gets overwritten with the new version. I'm not sure if that is what happens or is even necessary but it wasn't working before and I thought that might fix it but it didn't.

Some more info:

<*RootViewController.h*>

@interface RootViewController: UIViewController {
    UINavigationBar*navBar;
    UIWebView*webView;
}
@property (nonatomic, retain) UIWebView*webView;
@end

and

<*RootViewController.mm*>

#import "RootViewController.h";
@implementation RootViewController
- (void)loadView {
    //this is where I set up the webview, navigation bar, and button
}

@synthesize webView;

- (void)theButtonPressed {
    //this is where I try to update the index.html file
}

Please let me know what I am doing wrong and how to fix it or if you need any more information. Thanks!

mobabur94
  • 360
  • 2
  • 10

1 Answers1

0

Isn't the bundle read only, and you're trying to write to it.

Gruntcakes
  • 36,166
  • 41
  • 170
  • 346
  • So if I put it in the documents directory, it will work? I have it in the Resources folder right now so is that read only? – mobabur94 May 02 '12 at 10:28
  • Should work, give it a try. If you don't want the users to see/modify the files (via iTunes) use the application support directory, you can get a url link to it (or similar) using NSFileManager:URLForDirectory:NSApplicationSupportDirectory::: – Gruntcakes May 02 '12 at 14:32
  • Ok so I tried using the documents directory like this: [theData writeToFile:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"index.html"] atomically:NO]; But now the app crashes when I press the update button.. I tried using NSError but theos wouldn't compile it. – mobabur94 May 03 '12 at 00:32
  • I've no idea what theos is, but can you view output, or use NSLog. I'd check all the strings (or NSURLs if using them) contain what you expect them to. – Gruntcakes May 03 '12 at 15:16