-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (!isAuthenticated) {
isAuthenticated = false;
NSURL *url = [NSURL URLWithString:@"https://spo.mcd.com/sites/seeit_development3/brand/cognizant-test-brand-05242017"];`
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: self delegateQueue: [NSOperationQueue mainQueue]];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithUrl:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil) {
} else {
NSLog(@"Error: %@", error);
}
}];
[dataTask resume];
return NO;
}
return YES;
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler{
isAuthenticated = true;
NSURLCredential *cred = [NSURLCredential credentialWithUser:@"UserName"
password:@"Password"
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
completionHandler(NSURLSessionAuthChallengeUseCredential, cred);
NSLog(@"Finished Challenge");
}
执行上述操作后,我得到了一个响应,但URL从未在我的WebView中加载。
首先在此网址https://spo.mcd.com/sites/seeit_development3/brand/cognizant-test-brand-05242017
中首先显示一个登录屏幕,然后加载网页。
我获得了成功,但如何在Webview中加载此URL。尝试所有类型的ATS权限。没有什么工作