0

I have an iPhone app that uses the UIWebView to display a site that I have built as part of a much larger .net application. Everything was running beautifully until a change on my website side. Now what is happening in the iOS app is that the changes to fix the problem in the Website itself aren't appearing in the UIWebView. I verified the changes were in place by going into Safari on my iPhone with the exact same URL and all the changes were there. Why isn't the app recognizing the WebSite changes?

The code for loading the Website is below. Unfortunately I have to not include the actual URL. I'm fairly new to iOS so please be kind :)

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStyleBordered target:nil action:nil];
    [[self navigationItem] setBackBarButtonItem:backButton];

    // Set Logo in Navbar
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]];


    NSString *urlString = @"http://website.com/page.aspx";

    NSURL *url = [NSURL URLWithString:urlString];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [webView loadRequest:request];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

3 Answers3

0

modify your code with this

- (void)viewDidLoad {

    [super viewDidLoad];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@" "
                                                                   style:UIBarButtonItemStyleBordered
                                                                  target:nil
                                                                  action:nil];
    [[self navigationItem] setBackBarButtonItem:backButton];

    // Set Logo in Navbar self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]];

    NSString *urlString = @"http://website.com/page.aspx";

    NSURL *url = [NSURL URLWithString:urlString];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];

    [webView loadRequest:request];
}
Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15
0

Hey you could try out below line but this will be a good approach if website is changing contents in some time interval

[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:YOUR_WEBSITE_URL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0]];

Or you could simply

NSMutableURLRequest  *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strurl]];

[request setHTTPShouldHandleCookies:NO];

setHTTPshouldhandlecookie is made NO so no cookies will be saved and everytime it will go for remote resource.

Also for removing cookies from UIWebview check this link out. Hope helps you out !

Community
  • 1
  • 1
nikhil84
  • 3,235
  • 4
  • 22
  • 43
  • Tried that as well, still getting version of the site that no longer exists. I've checked it with all three levels of my code (testing, QA, and production version) and it still shows the old site info. – user3556295 Apr 21 '14 at 11:55
  • could you provide url along with screen shot of old and new website. So i could test it on my side for fix's. – nikhil84 Apr 21 '14 at 11:57
  • tried to email you, the old site is no longer accessible through the web. The new page that I see when browsing in Safari on my iphone has all of the changes but the Safari browser isn't sizing the page correctly. – user3556295 Apr 21 '14 at 12:31
  • Sizing is not problem of Safari browser its with website. You need to handle sizing from website dev point of view. Also without exactly knowing your need with website I won't be able to find fix's. Provide me new url and I will run a demo and provide you with screen shot of it so you could let me know of fix's. Cool ?¿ – nikhil84 Apr 22 '14 at 04:11
  • For some reason I can't find out how to email you the link. In any case, I've been working on this a little bit, and it's as if the site that was originally there is stuck in the cache of the app simulator, my iPhone, and anywhere else. I tried changing the URL and it picked up correctly, yet when I put the URL back to the original, it is still looking at the cached site. The URL is http://tracking.chpowell.com/ipa/logon.aspx . If you load that in safari on the login page you'll see a difference between that and what is on the UIWebView on the app itself. – user3556295 Apr 28 '14 at 11:57
  • ok it's irrelevant. After doing more testing, it's picking up the right pages. I think the problem lies elsewhere – user3556295 Apr 28 '14 at 12:20
  • @user3556295 great that you got your issue fixed. Also dude u could have voted up if my info was useful that would be nice. – nikhil84 May 01 '14 at 13:11
0

The problem is not that it is reloading. It's handling calls differently in the UIWebView than it is in Safari in the iPhone browser