Reputation: 20746
I'm trying to create an iOS application that requires authorization on some REST-service. What is the more appropriate structure of such application?
I think that there's should be smth like SignInViewController
with the appropriate text fields to enter username and password and I need to present it if one of the following conditions are met:
Ok, the first question is -- where should I place the code that checks the necessity of showing this view controller? In the func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
function?
The next question is -- how should I remember the user credentials entered in the last time? Should I save it to the iOS keychain with the key named smth like "LastEnteredUserCredentials"?
Then, where should I place the code that does an HTTP-request to the REST-service for the user authorization in both cases (first authorization ever or authorization with the saved user credentials)?
Is there any elegant examples of doing such things?
Thanks in advance.
Upvotes: 0
Views: 86
Reputation: 3764
applicationDidBecomeActive
AuthorizationManager
class, that contains all relevant code and generate notifications when the auth. status changed. Subscribe your app delegate to these notifications and let it present an appropriate view controller. Also the singleton could observe the UIApplicationDidBecomeActiveNotification
notification (from NotificationCenter) so there is no need to modify applicationDidBecomeActive
method of appDelegateUpvotes: 3