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!
Isn't the bundle read only, and you're trying to write to it.