Я пытаюсь получить доступ к защищенной веб-папке с веб-просмотром. с «жестко закодированным» пользователем и передайте его, но мой план состоит в том, чтобы открыть предупреждение, чтобы ввести пользователя и пройти. вот часть кода:Authentication Challenge
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge{
NSLog(@"Need Authentication");
UIAlertView *webLogin = [[UIAlertView alloc] initWithTitle:@"Authentication"
message:@"Enter User and Pass"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK"
, nil];
webLogin.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[webLogin show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
user = [[alertView textFieldAtIndex:0]text];
pass = [[alertView textFieldAtIndex:1]text];
NSLog(@"user is %@ and pass is %@",user,pass);
if (buttonIndex == [alertView cancelButtonIndex]) {
[self dismissModalViewControllerAnimated:YES];
}
else if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"OK Pressed");
[self handleAuthentificationOKForChallenge:nil withUser:user password:pass];
}
}
- (void)handleAuthentificationOKForChallenge:(NSURLAuthenticationChallenge *)aChallenge withUser:(NSString *)userName password:(NSString *)password {
NSURLCredential *credential = [[NSURLCredential alloc]
initWithUser:userName password:password
persistence:NSURLCredentialPersistenceForSession];
[[aChallenge sender] useCredential:credential forAuthenticationChallenge:aChallenge];
}
может кто-нибудь сказать мне, как назвать handleAuthenticationOKForChallenge I'ma немного запутанный с NSURLAuthenticationChallenge ....
еще, если исправлен :-) так, вы можете мне сказать, как инициализировать Ивар? myChallenge = [[NSURLAuthenticationChallenge alloc] initWith ...? – HugoBoss
Попытка: myChallenge = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge: вызов отправителя: challenge.sender]; –
не работает! все в порядке, чтобы иметь разные ценности вызова и mychallenge? – HugoBoss