2

UIWebViewiOSアプリでオフラインで実行するを作成しました。私は仮想ツアーを表示するために特定のjavascriptライブラリを利用しているので、を使用する必要がありますUIWebView

アプリケーションの実行時に問題が発生しました。リソースにないか、更新されているにもかかわらず、多くの場合、古い画像が表示されます。キャッシュポリシーの設定など、これを改善するために多くのことを試みました。

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];

私の一番上で、viewDidLoad私はキャッシュ容量を設定しようとしました:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];

そしてこれは私のアプリケーションdidFinishLaunchingWithOptionsで:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

現在、私はviewDidLoad

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];


    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
    [self.webView loadRequest:request];

    webView.frame = CGRectMake(0, 0, 1024, 768);

    webView.scalesPageToFit = NO;

    webView.multipleTouchEnabled = YES;

    for (id subview in webView.subviews)
        if ([[subview class] isSubclassOfClass: [UIScrollView class]])
            ((UIScrollView *)subview).bounces = NO;


    [super viewDidLoad];

私も試しましたviewDidLoad

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO]];

    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];


    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];


    [webView loadRequest:request];
    [self.view addSubview:webView];


    webView.scalesPageToFit = NO;

    webView.multipleTouchEnabled = YES;

    for (id subview in webView.subviews)
        if ([[subview class] isSubclassOfClass: [UIScrollView class]])
            ((UIScrollView *)subview).bounces = NO;


    [super viewDidLoad];

また、html5マニフェストに関係があるかどうかもわかりません。結局のところ、キャッシュをオフにして、現在リソースに存在するものを常に読み取るために必要なだけです。

4

0 に答える 0