NSURLCredentialStorage在iOS 7中不起作用

时间:2013-10-01 09:42:51

标签: ios7 windows-authentication nsurlcredential defaultnetworkcredentials nsurlcredentialstorage

希望我不是唯一的iOS 7受害者:)

我有一个应用程序将其数据库与我的Web服务同步,在我的同步流程中,使用Windows身份验证有14个Web服务调用。所有这些调用都在一个单独的线程中。我创建了一个通过URL返回NSData的自定义类。直到iOS7都运行良好,但在sharedCredentialStorage(NSURLCredentialStorage)中保存的新iOS版用户凭证不再有效。这是我的代码:

- (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);
}

如何在iOS7中使用NTLM凭据实现同步请求:(?

提前谢谢你, 最大

0 个答案:

没有答案