Reputation: 504
PREAMBLE
I am using Parse.com as a backend.
I have established registration and authentication functions to substantiate a PFUser.
I have established a log out button to reset the PFUser value to 0 ( zero ).
These functions exist on tangible view controllers separate to the nucleus of the application.
QUESTION
I want to create a user experience wherein:
Should the application be terminated whilst a PFUser has been substantiated:
The next time the application is opened:
The PFUser should be reinstated and directed to a particular view controller within the nucleus of the application. Rather than having to sign in all over again.
EXTRA
I suspect the following code to be applicable:
[ SOURCED FROM: PARSE IOS DOCUMENTATION: CURRENT USER ]
PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
// show application nucleus view controller
} else {
// show the signup / login view controller
}
in conjunction with the following:
[ SOURCED FROM: DEFAULT IOS APPLICATION DELEGATE ]
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
and
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}
OUTRO
Any pointers leading toward a solution are appreciated immensely. Thank you in advance for your help.
Upvotes: 1
Views: 128
Reputation: 2338
If the user is not logged out when the app is terminated, then they will be automatically logged in when the app is open again. In your login view controller's viewDidLoad method put:
if([PFUser currentUser])
{
//Code to go to view controller within app
}
Now, if the user did not log out before terminating the app, they will skip the login process.
Upvotes: 3
Reputation: 441
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UIViewController *NewViewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
UIViewController *LoginViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
if([PFUser currentUser])
{
[self.window setRootViewController:NewViewController];
}
else
{
[self.window setRootViewController:LoginViewController];
}
return YES;
}
Upvotes: 3