2013-01-17 58 views
0

我的目標是在iOS上使用UIWebView構建一個Web應用程序,基本上可以做BlackBerry爲Webworks所做的一切。iOS UIWebView緩存問題

閱讀後左右我留下不確定緩存是如何工作的,所以我嘗試了以下測試:

用的「Hello World」創建簡單的Web應用程序開始。

構建&運行應用程序 - 運行良好

然後改變了login.html的(那是什麼我的Hello World叫)我所做的更改是我reaplced的Hello World,並鏈接到另一個頁面。

當我建立&再次運行舊頁面仍然顯示。

所以我假設有緩存的地方?

有無論如何去做以下/什麼是最好的?

  • 禁用緩存爲速度並不重要我們所有的文件都在磁盤上?
  • 每次啓動應用程序時清除緩存?

有沒有人遇到過這個?

感謝

我曾嘗試: How to delete the cache from UIWebview or dealloc UIWebview

另一個更新------

嘗試另一種簡單的測試,我刪除了我的HTML文件夾中所有的HTML,CSS,JS文件在它現在在垃圾中。再次運行該應用程序並刪除項目中的html引用,它仍然會加載它們全部完美。所以整個事情都緩存在某個地方。

至於另一次嘗試,我也補充說:

-(void)dealloc{ 
    self.webView.delegate = nil; 
    self.webView = nil; 
    [webView release]; 
    [super dealloc]; 
} 

在NativeViewController.m這並沒有幫助。

我的應用程序代碼:`

#import "NativeViewController.h" 

@implementation NativeViewController 

@synthesize webView; 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
[super viewDidLoad]; 

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"login" ofType:@"html"]; 
NSData *htmlData = [NSData dataWithContentsOfFile:filePath]; 
if (htmlData) { 
    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *path = [bundle bundlePath]; 
    NSString *fullPath = [NSBundle pathForResource:@"login" ofType:@"html" inDirectory:path]; 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]]; 

} 
} 


- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
[self.webView removeFromSuperview]; 
self.webView.delegate = nil; 
self.webView = nil; 
} 


-(void)webViewDidFinishLoad{ 
[[NSURLCache sharedURLCahce] removeAllCachedResponses]; 
} 
- (void)dealloc { 
[webView release]; 
[super dealloc]; 
} 
@end 

`

+0

你的.html文件是捆綁在一起的嗎? – Dhara

+0

是在構建階段,包含所有HTML文件的文件夾在那裏:它說:「複製束資源」「HTML」,帶有藍色文件夾圖標,然後是MainWindow.xib,NativeViewController.xib,MainWindow-iPad。包中的xib – LmC

+0

是否意味着它已添加到您的項目中?做一個事情重置模擬器,然後嘗試 – Dhara

回答

1

嘗試此

if ([htmlData length]==0) { 
//no data 
} 

這將不加載的數據,如果其長度爲0 在其它情況下,即使如果你將從你的項目中移除html文件,它將會出現在模擬器中,除非你d o不重置它。

希望它有幫助。

1
Yes..I encountered the same problem..  
I solved it by adding the below statement in didFinishLaunchingWithOptions method of AppDelegate class 

    [[NSURLCache sharedURLCache] removeAllCachedResponses]; 
+0

仍舊顯示我的舊HTML文件。 ..即使我從捆綁軟件和硬盤中刪除它,並運行應用程序它仍然存在 – LmC

+0

把這個在webViewDidFinishLoad方法和檢查一次.. – Murali

+0

我不明白你的意思是我的檢查一次? – LmC