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 正确处理重定向?
为了从一个站点重定向到另一个站点,只需加载您的网站,但添加一个 BOOL var 来检查是否加载了正确的页面。
BOOL page1Loaded;
然后,如果您需要更改到另一个站点,只需创建一个全局 NSString var,如下所示
// for site name
NSString *urlAddress;
并在需要时更新
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];
}
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)