webview遇到重定向问题 [英] webview having trouble with redirects
本文介绍了webview遇到重定向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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正确处理重定向?
The UIWebView is having trouble with redirects. How can I make sure the uiwebview handles redirects properly?
推荐答案
为了从一个站点重定向到另一个站点,只需加载您的网站,但添加BOOL var以检查是否加载了正确的页面。
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;
然后,如果您需要更改到另一个站点,只需创建一个全局NSString var
then, if you need to change to another site, just create a global NSString var like so
// 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];
}
希望这有帮助!
这篇关于webview遇到重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文