Update: This issue is fixed in iOS 7.0.3
I answered this on the Apple Developer Forum, but now that iOS7 is coming out of beta, I will rearrange it here. Windows authentication is currently broken in iOS7. I expect it to be fixed soon, but until then you can work around this problem by accessing the authentication tasks in your UIViewController, which contains your UIWebView.
Essentially you
- Do NSURLRequest and NSURLConnection by yourself
- Handle connection: didReceiveAuthenticationChallenge:
- In connection: didReceivedResponse manually loads your data into a UIWebView
Below I upload a PDF file, but this process works regardless of your content type.
//Make sure you implement NSURLConnectionDelegate and NSURLConnectionDataDelegate in your header @interface MyViewController () @property (weak, nonatomic) IBOutlet UIWebView *webView; @property (strong, nonatomic) NSURLConnection *conn; @property (strong, nonatomic) NSMutableData *pdfData; @end @implementation MyViewController //... all of your init and other standard UIViewController methods here... //Method that loads UIWebview. You'll probably call this in viewDidLoad or somewhere similar... - (void) loadWebView { //Make Request manually with an NSURLConnection... NSString *url = //Get your url NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; self.conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; } //#pragma mark - NSURLConnectionDelegate //Handle authentication challenge (NSURLConnectionDelegate) - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { if([challenge previousFailureCount] == 0) { NSString *username = //Get username NSString *password = //Get password //Use credentials to authenticate NSURLCredential *cred = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistencePermanent]; [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge]; } else { //Cancel authentication & connection [[challenge sender] cancelAuthenticationChallenge:challenge]; [self.conn cancel]; self.conn = nil; } } //#pragma mark - NSURLConnectionDataDelegate //Received response (NSURLConnectionDataDelegate) - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { //Init data self.pdfData = [NSMutableData data]; } //Collect data as it comes in (NSURLConnectionDataDelegate) - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [self.pdfData appendData:data]; } //Handle connection failure (NSURLConnectionDataDelegate) - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { //Clean up... [self.conn cancel]; self.conn = nil; self.pdfData = nil; //TODO: Notify user and offer next step... } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { //Finally, load data into UIWebview here (I'm loading a PDF)... [self.webView loadData:self.pdfData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; } @end
source share