【发布时间】:2014-12-27 12:39:47
【问题描述】:
我有一个 webview 加载时,用户通过 POST 请求登录。他们登录后,我希望他们被带到一个网页。我的 POST 请求是一个如下 URL:
- (void)viewDidLoad {
[super viewDidLoad];
[_scoreWebView setDelegate:self];
NSMutableURLRequest *detailRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"myrul"]];
[detailRequest setHTTPMethod:@"POST"];
NSString *sendInfo =[NSString stringWithFormat:@"action=login&EMAIL=email&PASSWORD=password", nil];
NSData *infoData = [sendInfo dataUsingEncoding:NSUTF8StringEncoding];
[detailRequest setHTTPBody:infoData];
[_scoreWebView loadRequest:detailRequest];
}
此登录过程运行良好。但是,在我将用户发送到我的网页后,它会无限启动 webviewdidfinishload。我知道每次加载某些东西时它都会触发。登录后是否有替代解决方案将用户重定向到我的页面?此外,我有三个不同的页面,用户可以根据他们的输入被重定向到,这只是其中之一,为简单起见。这是我的完成加载方法:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//Check here if still webview is loding the content
if (webView.isLoading)
return;
else //finished
NSLog(@"finished loading");
NSLog(@"%@ in calendar", _thisScriptUniqueID);
NSString *fullURL=[NSString stringWithFormat:@"myurl/%@#score", _thisScriptUniqueID];
NSLog(@"%@", fullURL);
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_scoreWebView loadRequest:requestObj];
}
是否可以使用不同的方法将用户带到页面,或者是否可以将两者都包含在 viewDidLoad 中?
【问题讨论】:
标签: ios objective-c xcode uiwebview