HTMLファイルを表示し、サーバーから新しいバージョンをダウンロードしてローカルHTMLファイルを更新するボタンがナビゲーションバーにある単純なアプリケーションを作成しようとしています(デバイスでtheosを使用しているため、xcode/macは使用せず、ifileのみ)既存のものを上書きします。私の問題は、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
}
私が間違っていることとそれを修正する方法、またはさらに情報が必要な場合はお知らせください。ありがとう!