I’m new to obj-c/iOS/parse so this is a basic question.
I’ve managed to get the login and sign up controllers to appear in my code, but I don’t understand where does the hook go to start my own game code, once the user has signed up/logged in? In the parse iOS guide you have code examples like this…
PFUser *currentUser = [PFUser currentUser];
if (currentUser) {
// do stuff with the user
} else {
// show the signup or login screen
}
or…
[PFUser logInWithUsernameInBackground:@"myname" password:@"mypass" block:(PFUser user, NSError error) {
if (user) {
// Do stuff after successful login.
} else {
// The login failed. Check error to see why.
}
}];
But I don’t see similar code in the login/sign up tutorial code, just something about protocols and delegates?
your kind of mixing the old manual login approach with the fairly new viewcontroller approach, although both are still valid.
If you follow the tutorial, use the test on PFUser to decide if you should show the login controller. If you are new to IOS, then you will need to brush up on protocols and delegates because its a pattern you will see used frequently.
Basically, a protocol is pre-defined set of methods that allow two objects to work together, while knowing very little about each other. So it allows objects to be very modular and abstract. A delegate is a way that one object informs the other that is wants to work together using the protocol.
When you fire up the parse login view controller, you have to set yourself as its delegate, once you do that, you can receive messages from it about the success or failure of someone logging in.
So, you simply fire it up, set yourself as the delegate then present it.
when a user logins in successfully, the parse login view controller will send a message to you looking for a certain method to exist. If you have it, then it will be called (or possibly crash if not). So in this case, in your view controller that is presenting the parse login view controller, you should also implement (by having them there) the login success method and login failure method. I show the login success method below. If you implement that, the first line dismisses the login view controller. you would then add a method call to start your program possibly in the completion block or just below it.
}