UIWebView + Sharepoint + NTLM身份validation – 我得到stream是在打开之前发送一个事件

我一直在一个有一个简单的UIWebView的应用程序,它显示一个Sharepoint网站。 我原本以为NTLMauthentication是一个问题,但事实certificate这是非常简单的。 然而,自iOS8以来,我的应用程序一直在垃圾邮件“stream正在打开之前发送一个事件”一遍又一遍在我的日志中,该网页真的永远不能加载。

我原本以为这是我正在做的事情,所以我创build了一个小应用程序(下)以消除我的其他应用程序可能有的任何古怪,但不幸的是,我得到同样的问题。 我想我的主要问题是我不知道该从哪里开始寻找答案。 互联网有一些提到这个,但没有像[webView dontDoThat]清晰的决议。 :d

我正在玩手动添加连接到运行循环,你会在代码中看到这个。 我已经尝试了各种方式,我知道如何创build连接,但这是最近的尝试。

我开始处理SSL挑战,因为我的证书对域无效,于是我得到NTLM挑战,并发送硬编码的用户名,并通过testing。 它部分加载网站,但最终放弃加载所有的资源,我认为是这个错误。 理论的欢迎。

// // ViewController.m // // Created by Greg Frame on 10/2/14. // #import "ViewController.h" #define APPURL @"https://mysharepoint.com" #define USERNAME @"usernamehere" #define PASSWORD @"passwordhere" @interface ViewController () @end @implementation ViewController BOOL _Authenticated = NO; BOOL _SSLAuthenticated = NO; NSURLConnection *_Connection; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.webView.delegate = self; NSURLRequest *requestURL = [NSURLRequest requestWithURL:[NSURL URLWithString:APPURL]]; [self.webView loadRequest:requestURL]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark UIWebViewDelegate -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if(webView.loading){ //if url requests come through while its loading, its probably embedded content return YES; } BOOL result = YES; if (!_Authenticated || !_SSLAuthenticated) { //I have tried a ton of different ways to create the NSURLConnection this is the latest _Connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [_Connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; [_Connection start]; result = NO; } return result; } #pragma mark NSURLConnection Delegate -(void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge { if( [challenge previousFailureCount] == 0 ) { if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { NSLog(@"SSL Challenge"); NSURL* baseURL = [NSURL URLWithString:APPURL]; if ([challenge.protectionSpace.host isEqualToString:baseURL.host]) { NSLog(@"trusting connection to host %@", challenge.protectionSpace.host); [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; } else NSLog(@"Not trusting connection to host %@", challenge.protectionSpace.host); } else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM]) { NSLog(@"NTLM Challenge"); _SSLAuthenticated = YES; //cant get here otherwise //persistence:NSURLCredentialPersistenceForSession NSURLCredential *cred = [NSURLCredential credentialWithUser:USERNAME password:PASSWORD persistence:NSURLCredentialPersistencePermanent]; [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge]; } else { NSLog(@"Unsupported Challenge"); [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge]; } } else { NSLog(@"Failed authentication"); [[challenge sender] cancelAuthenticationChallenge:challenge]; } } -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)pResponse { NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)pResponse; NSLog(@"Received response %ld", (long)[httpResponse statusCode]); if( !_SSLAuthenticated && [httpResponse statusCode] == 200) { NSLog(@"SSL GOOD"); _SSLAuthenticated = YES; [_Connection cancel]; _Connection = nil; NSURLRequest *requestURL = [NSURLRequest requestWithURL:[NSURL URLWithString:APPURL]]; [self.webView loadRequest:requestURL]; return; } if( !_Authenticated && [httpResponse statusCode] == 200) { NSLog(@"NTLM GOOD"); _Authenticated = YES; [_Connection cancel]; [_Connection unscheduleFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; NSURLRequest *requestURL = [NSURLRequest requestWithURL:[NSURL URLWithString:APPURL]]; [self.webView loadRequest:requestURL]; return; } NSLog(@"Connection Cancelled"); [_Connection cancel]; } @end 

免责声明:零件和零件是从其他人复制的,所以我不声称已经手动input每一行。 感谢你们所有的代码,我把这个例子。

任何帮助感激! – 格雷格框架

一些日志条目:

  2014-10-06 15:12:31.110 sptest2[21405:2051411] SSL Challenge 2014-10-06 15:12:31.110 sptest2[21405:2051411] trusting connection to host xxxxx.xxxxx.com 2014-10-06 15:12:31.426 sptest2[21405:2051411] NTLM Challenge 2014-10-06 15:12:31.899 sptest2[21405:2051690] Stream 0x7c8d9070 is sending an event before being opened 2014-10-06 15:12:32.429 sptest2[21405:2051411] Received response 200 2014-10-06 15:12:32.429 sptest2[21405:2051411] NTLM GOOD 2014-10-06 15:12:33.184 sptest2[21405:2051723] Stream 0x7ca95210 is sending an event before being opened 2014-10-06 15:12:34.293 sptest2[21405:2051723] Stream 0x7bed9740 is sending an event before being opened 2014-10-06 15:12:34.465 sptest2[21405:2051723] Stream 0x7bee1120 is sending an event before being opened 2014-10-06 15:12:34.523 sptest2[21405:2051723] Stream 0x7caba9a0 is sending an event before being opened 2014-10-06 15:12:34.532 sptest2[21405:2051723] Stream 0x7f87e040 is sending an event before being opened ...