현재 잘 작동하는 내 iPhone 앱의 URL에서 이미지를로드하고 있습니다. 하지만 이제 보호 된 URL에 액세스하려고합니다. 자격 증명 (사용자 이름/암호)을 사용하여 URL에 액세스하는 방법을 알려주는 코드 조각으로 안내해주십시오.iOS에서 인증이 필요한 URL에 액세스하는 방법
내 애플 URL에서 이미지를로드되는 간단한 코드는이 두 콜백
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
// IF to handle NTLM authentication.
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodNTLM])
return YES;
// Mostly sent by IIS.
if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust])
return YES;
return NO;
}
- (void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
{
if ([[[challenge protectionSpace] authenticationMethod] isEqual:NSURLAuthenticationMethodNTLM])
{
[[challenge sender] useCredential:[NSURLCredential
credentialWithUser:Username
password:password
persistence:NSURLCredentialPersistenceNone]
forAuthenticationChallenge:challenge];
}
else if ([[[challenge protectionSpace] authenticationMethod] isEqual:NSURLAuthenticationMethodServerTrust])
{
[[challenge sender] useCredential:[NSURLCredential
credentialWithUser:Username
password:password
persistence:NSURLCredentialPersistenceNone]
forAuthenticationChallenge:challenge];
}
else
{
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
}
나는 이것을 시도했지만 didReceiveAuthenticationChallenge 콜을 다시 호출하지 않는다. – Sublime