0
NSURL *urlString = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];

//Load the request in the UIWebView.
[self.webview loadRequest:requestObj];

UIWebView 在重定向时遇到问题。如何确保 uiwebview 正确处理重定向?

4

1 回答 1

0

In order to do a redirect from one site to another, just load your website, but add a BOOL var for checking if the right page is loaded.

 BOOL page1Loaded;

then, if you need to change to another site, just create a global NSString var like so

 // for site name
 NSString *urlAddress;

and just update upon needing to

 if(page1Loaded) {

    // as seen in @Lithu T.V.'s comment, DO NOT FORGET the http:// or https://
    // name of address 
    urlAddress = @"http://..." or @"https://..."

    NSString *urlString = [NSURL URLWithString:urlAddress];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];

    //Load the request in the UIWebView.
    [self.webview loadRequest:requestObj];
 }
 else {

    // as seen in @Lithu T.V.'s comment, DO NOT FORGET the http:// or https://
    // name of redirect 
    urlAddress = @"http://..." or @"https://..." 

    NSString *urlString = [NSURL URLWithString:urlAddress];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];

    //Load the request in the UIWebView.
    [self.webview loadRequest:requestObj];
 }

hope this helps!

于 2013-07-25T01:08:00.133 回答