开发者

How and where to perform login process (in this case getting token from server) in iPhone app?

开发者 https://www.devze.com 2022-12-20 00:46 出处:网络
So what I need to do in my application for loggin in is Perform an HTML request with user/pass which returns开发者_如何转开发 XML with a token. The token is used in later http requests.

So what I need to do in my application for loggin in is Perform an HTML request with user/pass which returns开发者_如何转开发 XML with a token. The token is used in later http requests.

I know how to perform http requests and also how to parse them, I have already been doing that just with the token hardcoded for testing purposes. I also have it worked out how to use the Application Preferences to allow entry and retreval of the password via:

NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"<Setting Key>"]

The question is if I want this to happen when the application launches where shall I do this? I don't want my application to hang when it launches without giving some feedback to the user, you know if there is no user/pass set or if its rejected by the server. What is your advice? Thanks


In the app that I am developing, I do it in the first view in a separate thread. This way it doesn't lock the UI. I also do it as a delegate of the main view so it can report back the progress for a progress bar. Later on I'll will be doing it as a slide in view thats just shaded so the person can use parts of the app that don't require auth while the auth is loading.

IMO if you do it in the app delegate it might take several seconds for you to auth and you will not be able to report this to the user easily.

The best way to deal with authentication is using cookies as you are using HTML requests. You can retrieve these cookies using NSHTTPCookieStorage app wide (not just in the class that did the authentication). If you want to continue using your token you can create a global variable in your Application Delegate class (myApplicationAppDelegate.h)

P.S, I wouldn't keep the username and password in NSUserDefaults as its stored in plain text on the device. Use keychain instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消