0

My aim is to build a web application using UIWebView on iOS, basicly doing what BlackBerry do for Webworks.

After reading around I'm left unsure about how cache worked so i tried the following test:

Created simple web application with "Hello World" to begin.

Build & Ran the application - Worked fine

Then changed the login.html (thats what my hello world was called) The changes i made was i reaplced hello world with a hyperlink to another page.

When i Build&Run again the old page is still display.

So im assuming there's caching somewhere?

Is there anyway to do the following/whats best?

  • Disable caching as speed isnt important all our files are on disk?
  • Clear the cache every time we launch the application?

Has anyone encountered this before?

Thanks

I have tried: How to delete the cache from UIWebview or dealloc UIWebview

Another update ------

Tried another simple test, i deleted my HTML folder with all the html,css,js files in it so its now in trash. Ran the application again and delete html references from the project and it still loads them all perfect. So the whole thing is cached somewhere.

As another try i have also added:

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

In NativeViewController.m this did not help.

My applications code:`

#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

`

Community
  • 1
  • 1
Lemex
  • 3,772
  • 14
  • 53
  • 87
  • your .html file is in bundle? – Dhara Jan 17 '13 at 09:32
  • Yes in the Build phases the folder containing all HTML files is there: it says "Copy bundle resources" "HTML" with blue folder icon then MainWindow.xib, NativeViewController.xib, MainWindow-iPad.xib – Lemex Jan 17 '13 at 09:35
  • in bundle means its added in your project? Do a thing reset simulator and then try – Dhara Jan 17 '13 at 09:58
  • Deleted all html files from proejct and disk ran it and it still showed them – Lemex Jan 17 '13 at 10:16
  • Show the code how ur loading the html page – Dhara Jan 17 '13 at 10:22
  • Updated to show the code – Lemex Jan 17 '13 at 10:29
  • All code now added hope this helps – Lemex Jan 17 '13 at 10:34
  • The new hello world is shown with hyperlinked? – Dhara Jan 17 '13 at 10:40
  • What sorry? The code above seems to remember the cahce in both simulator and iPad device. I've even delete the files of xcode project and the hard disk. So when its built it includes no html files what so ever but still pulls the old ones from the cache. I wish to disable the cache in my UiWebview all together or at least every time the app is built/starts – Lemex Jan 17 '13 at 10:43
  • I tried the way you told but i found that if i make a change in the .html file i the webview loads the new html file only. Open your simulator,Click on simulator-> Reset Content and Settings and then click on reset and then run – Dhara Jan 17 '13 at 10:51
  • I agree with what your saying reset content works... But that doesnt solve the caching issue on the device – Lemex Jan 17 '13 at 10:55
  • See if you are making changes and loading webview new data will only come so there is no way to remove the data and then running on simulator without reseting the simulator. I dont know why u are doing that – Dhara Jan 17 '13 at 11:02
  • After removing the html directory and readding the files/folder in the group it seems to be working again – Lemex Jan 17 '13 at 11:02
  • so ur issue is solved right? – Dhara Jan 17 '13 at 11:04
  • So far will continue some testing and make sure. Are you an experience iOS developer? I need some advice about automated builds.. – Lemex Jan 17 '13 at 11:07
  • Can you have a look here? http://stackoverflow.com/questions/14377903/ios-xcode-automated-command-line-build Im 2/3 out of completeing automated iOS builds(similar to phone gap) – Lemex Jan 17 '13 at 11:19

2 Answers2

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

  [[NSURLCache sharedURLCache] removeAllCachedResponses];
Murali
  • 188
  • 1
  • 11
1

Try this

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

This will not load the data if its length is 0. In other conditions even if you will remove the html file from your project it will be there in the simulator unless you do not reset it.

Hope it helps.

Dhara
  • 4,093
  • 2
  • 36
  • 69