我正在尝试创建一个简单的应用程序(在我的设备上使用theos,因此没有xcode / mac,只是ifile ),它显示一个HTML文件,并在导航栏中有一个更新本地的按钮从服务器下载新版本并覆盖现有版本的HTML文件。 我的问题是 HTML文件的较新版本无法下载,现有版本保持不变。
按下按钮时,这是我必须尝试并更新本地HTML文件的代码:
[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]]];
blank.html是一个空白的HTML文件。我把它放在那里所以我可以刷新index.html并且还有index.html没有使用白色它被新版本覆盖。我不确定这是发生了什么甚至是必要的,但它之前没有工作,我认为可能会解决它,但事实并非如此。
更多信息:
<*RootViewController.h*>
@interface RootViewController: UIViewController {
UINavigationBar*navBar;
UIWebView*webView;
}
@property (nonatomic, retain) UIWebView*webView;
@end
和
<*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
}
请让我知道我做错了什么以及如何解决或者您需要更多信息。谢谢!
答案 0 :(得分:0)
捆绑包不是只读的,而您正在尝试写入它。