views:

308

answers:

2

Hi Team,

Had a question related to best practices in iPhone login authentication using asynchronous NSURLConnection.

Since the same delegate is used for logging into a server, how do folks differentiate notifications coming back for an authentication request, versus when you recieve data for subsequent data requests?

Thanks,

Sj

+1  A: 

If by authentication, you mean HTTP authentication, then that is not handed back to you as data. It comes back in -connection:didReceiveAuthenticationChallenge:. If you're talking about a higher-level protocol that manages authentication above the HTTP layer, then it's your job to keep track of the current state of your connection.

See Using NSURLConnection for full details on HTTP Auth.

Rob Napier
So I've got auth working, what I don't understand is how to differentiate didRetrieveData for different requests. What I'm wondering about is how do you differentiate a didRetrieveData for an auth request, versus the same for a request of another nature (fetching json for ex).Thanks Rob.
If we're talking HTTP Auth, then you shouldn't get didReceiveData an an HTTP auth challenge. What kind of auth request are your referring to?
Rob Napier
A: 

The common pattern to use would be to create a different class for each type of request you have and make it manage the lifetime its own NSURLConnection. It can then send events back to its delegate.

The other method would be to remember all the NSURLConnections you've created and compare them against the first parameter of the delegate callbacks.

rpetrich