hope i'm not unique iOS 7 victim :)
I have an application that synchronize its database with my web service, in my synchronization flow there is 14 call to web services, using Windows Authentication. All this call are inside a separate thread. I created a custom class that return NSData by URL. Till iOS7 all worked fine, but with new iOS version user credential saved in sharedCredentialStorage (NSURLCredentialStorage) no longer work. Here is my code:
- (BOOL)isValidURL:(NSString *) stringUrl forUsername:(NSString*) username andPassword:
(NSString*) password andDomain:(NSString*) _domain
{
username = [_domain stringByAppendingFormat:@"\\%@",username];
NSURLCredential *credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession ];
//------------search host, port for credential storege......
NSArray *dati = [self getHostAndPortFromUrl:stringUrl];
if(dati==nil)
return FALSE;
//this info are correct
NSString *host = [dati objectAtIndex:0];
NSNumber *port = [dati objectAtIndex:1];
//-----------------------------------------------------------
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:host port:port.intValue protocol:@"http" realm:host authenticationMethod:NSURLAuthenticationMethodNTLM];
[[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace];
//creadentials are saved
NSLog(@"%@",[[NSURLCredentialStorage sharedCredentialStorage] allCredentials]);
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",stringUrl]];
NSURLRequest *req = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:25.0];
NSHTTPURLResponse *res = nil;
NSError *err = nil;
[NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err ];
//here i receive error: Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)"
//show alert view if error
[self showMsgBasedOnError:err andResponce:res];
//NSLog(@"url valid = %@\n", ((err==nil && [res statusCode]!=404) ? @"YES" : @"NO"));
return (err==nil && [res statusCode]!=404);
}
How I can implement an synchronous request using NTLM credentials in iOS7 :( ?
Thank you in advance, Max