I am writing a Parse app and using the Parse LoginViewController and SignUpViewController. I have been using the SubclassConfigViewController as a model from their LoginAndSignUp demo. As they talk about in their documentation, I want to check the username and password for various things before the signUp commences. This should take place in the delegate function "signUpViewControllerShouldSignBeginSignUp"
But, it is not being called and the app signs up anybody. It checks only that at the email is in a valid format and that a user name exists. I have put a println (Swift) at the beginning of the function. It never prints.
What can I do to force this function to run?
The "loginViewControllerShouldLogInUser" runs as expected.
Here is my code:
class LoginConfigViewController: UIViewController, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate
{
var loginViewController: LoginViewController! = LoginViewController()
var signUpViewController: SignUpViewController! = SignUpViewController()
override func viewWillAppear(animated: Bool)
{
if (PFUser.currentUser() == nil)
{
loginViewController.delegate = self
loginViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.DismissButton
//signUpViewController.delegate = self;
signUpViewController.fields = PFSignUpFields.Default | PFSignUpFields.Additional | PFSignUpFields.DismissButton
loginViewController.signUpController = signUpViewController;
loginViewController.signUpController?.delegate = self
self.presentViewController(self.loginViewController, animated: false, completion: nil)
}
else
{
self.dismissViewControllerAnimated(false, completion: nil)
}
}
// MARK: - PFLogInViewControllerDelegate
func logInViewController(logInController: PFLogInViewController!, shouldLogInUser user: PFUser!, password: String!) -> Bool {
println("shouldLogIn...")
return true
}
func logInViewController(logInController: PFLogInViewController, shouldBeginLogInWithUsername username: String, password: String) -> Bool {
println("should login in \(username)")
return true
}
@IBAction func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) {
println("didLogInUser \(user.username)")
self.loginViewController.dismissViewControllerAnimated(false, completion: nil)
}
// Sent to the delegate when the log in screen is dismissed.
func logInViewControllerDidCancelLogin(logInController: PFLogInViewController!) {
println("User dismissed the logInViewController")
self.loginViewController.dismissViewControllerAnimated(false, completion: nil)
}
// MARK: - PFSignUpViewControllerDelegate
// Sent to the delegate to determine whether the sign up request should be submitted to the server.
func signUpViewControllerShouldBeginSignUp(signUpViewController: PFSignUpViewController!, info: NSDictionary) -> Bool {
println("signUpViewController::shouldBeginSignUp")
return true
}
// Sent to the delegate when a PFUser is signed up.
func signUpViewController(signUpViewController: PFSignUpViewController, didSignUpUser user: PFUser) {
println("didSignUpUser \(user.username)")
user.removeObjectForKey("additional")
self.signUpViewController.stopAI()
self.signUpViewController.dismissViewControllerAnimated(false, completion: nil)
self.loginViewController.dismissViewControllerAnimated(false, completion: nil)
}
// Sent to the delegate when the sign up attempt fails.
func signUpViewController(signUpViewController: PFSignUpViewController!, didFailtoSignUpWithError error: NSError) {
println("Failed to sign up...")
}
// Sent to the delegate when the sign up screen is dismissed.
func signUpViewControllerDidCancelSignUp(signUpViewController: PFSignUpViewController) {
println("User dismissed the signUpViewController")
signUpViewController.dismissViewControllerAnimated(false, completion: nil)
}
//MARK: - ()
func logOutButtonTapAction(sender: AnyObject) {
PFUser.logOut()
self.dismissViewControllerAnimated(false, completion: nil)
}
}
答案 0 :(得分:0)
我遇到了完全相同的问题,默认解析登录和注册控制器不会对其指定的方法起作用。经过数小时和数小时的故障排除并且无法找到答案,结束时不使用默认的解析用户界面并创建我自己的解决方案用户界面并且工作正常并且可以解析得很好。以下是Youtube Video,其中显示了自定义登录所需的代码。由于某种原因,他们的方法不会打电话而且令人沮丧。一旦用户登录,我就使用了一个segue到我的Home视图控制器。
self.actInd.startAnimating()
PFUser.logInWithUsernameInBackground(username, password: password, block: { (user, NSError) -> Void in
self.actInd.stopAnimating()
if ((user) != nil) {
println("success user logged in")
self.performSegueWithIdentifier("toHome", sender: self)
}else {
var alert: UIAlertView = UIAlertView(title: "error", message: "You are logged in already", delegate: self, cancelButtonTitle: "Ok")
alert.show()
}
希望有所帮助。 祝你好运!
答案 1 :(得分:0)
我有同样的问题,试试这个:
let logInController = LogInViewController()
let signUpController = SignUpViewController()
logInController.delegate = self
signUpController.delegate = self
logInController.signUpController = signUpController