webview having trouble with redirects

百般思念 提交于 2019-12-02 10:53:11

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!