I have a custom UIViewController shown with presentModalViewController function in a http basic authentication delegate to get username and password. I want to wait till the user clicked the login button on the modal view controller shown on the screen. How can I do this? I am new to iOS any comments or links would be appreciated.
Edit : here is a sample code inside NSURLConnectionDelegate
-(void) connection(NSURLConnection*)connection willSendRequestForAuthenticationChallenge(NSURLAuthenticationChallenge*)challenge
{
CustomAuthViewController *authView = [CustomAuthViewController alloc] initWithNibName"@"CustomAuthViewController" bundle:[NSBundle mainBundle]];
[parentcontroller presentModalViewController:authView animated:YES];
//
// I want to wait here somehow till the user enters the username/password
//
[[challenge sender] userCredentials:credentials forAuthenticationChallenge:challenge];
}
Kind regards.
Edit : Solution : It is not necessary to send the credentials in the willSendRequestForAuthenticationChallenge delegate function right away. I can send it anytime later, It is strange though.
Basically what you want is to pass a message from the modal UIViewController to the caller when your login dialog completes. There are a number of ways to do this. Here’s a couple:
Option 1 – Delegate Pattern:
On your modal dialog .h
On your modal dialog .m
in your init:
in your dealloc:
when you complete your login:
Then on your calling view controller implement the LoginDelegate protocol.
And when you create your login view controller, set the delegate:
Option 2 – Post a notification with NSNotificationCenter:
On your login dialog:
On your calling view controller
Then you implement the selector loginComplete.
If you want to pass back login information (username, userId, etc) you can package that into a dictionary and add it as the “object” in the postNotificationName method.
You also need to be sure to call
when you are done listening.