Ios UIWebView&x2B;Sharepoint+;NTLM Auth-I get流在打开之前正在发送事件
我一直在开发一个应用程序,其中包含一个简单的UIWebView,可以显示Sharepoint网站。我原本以为NTLM身份验证会是一个问题,但事实证明,这是非常直接的。然而,自从iOS8以后,我的应用程序在我的日志中一次又一次地发出垃圾邮件“Stream在打开之前发送事件”,以至于页面真的无法加载 我最初认为这是我正在做的事情,所以我创建了一个小应用程序(如下),以消除我的其他应用程序可能存在的任何奇怪之处,但不幸的是,我遇到了同样的问题。我想我的主要问题是我不知道从哪里开始寻找答案。互联网对此有所提及,但没有明确的解决方案,如[webView dontDoThat]:D 我正在尝试手动将连接添加到运行循环,您将在代码中看到这一点。我已经尝试了所有我知道如何创建连接的方法,但这是最近的一次尝试 我开始处理SSL挑战,因为我的证书对域无效,然后我得到NTLM挑战并发送硬编码用户名,作为测试通过。它部分加载站点,但最终放弃加载所有资源,我认为这是一个错误。欢迎你Ios UIWebView&x2B;Sharepoint+;NTLM Auth-I get流在打开之前正在发送事件,ios,sharepoint,ssl,uiwebview,ntlm,Ios,Sharepoint,Ssl,Uiwebview,Ntlm,我一直在开发一个应用程序,其中包含一个简单的UIWebView,可以显示Sharepoint网站。我原本以为NTLM身份验证会是一个问题,但事实证明,这是非常直接的。然而,自从iOS8以后,我的应用程序在我的日志中一次又一次地发出垃圾邮件“Stream在打开之前发送事件”,以至于页面真的无法加载 我最初认为这是我正在做的事情,所以我创建了一个小应用程序(如下),以消除我的其他应用程序可能存在的任何奇怪之处,但不幸的是,我遇到了同样的问题。我想我的主要问题是我不知道从哪里开始寻找答案。互联网对此有
//
// 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
免责声明:零件和零件是从别人那里复制的,所以我并不声称每一行都是手动输入的。感谢所有拥有我在本例中输入的代码的人
感谢您的帮助!
-格雷格框架
一些日志条目:
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
...
这里也有同样的错误。运气好吗?作为一项测试,我为每个页面加载创建了一个NSURLConnection,并开始注意到sharepoint在加载时请求几个不同文件的凭据,看起来是随机的。我认为这就是导致页面永远无法加载的原因。信息本身可能不是一个巨大的考验。一个建议是,如果您不需要支持iOS7x,那么使用WkWebView,它有委托来处理内置的NTLM auth。这在iOS8上对我很有效。不幸的是,我在格雷加特又被困了3-4个月。这里WKWebView也不起作用。请给我看一下简单的代码。