Dismiss parseUI login view from a SKScene

129 views Asked by At

I am using ParseUI inside a SpriteKit Swift app.

This is my LoginScene

class LoginScene: SKScene, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate {

    func showLoginView() {
        let nativeLogin = NativeLoginViewController()
        nativeLogin.fields = PFLogInFields.Default
        nativeLogin.delegate = self
        self.view?.window?.rootViewController?.presentViewController(nativeLogin, animated: true, completion: nil)
    }

    func logInViewController(logInController: PFLogInViewController!, didLogInUser user: PFUser!) {
        println("login succeeded")
            self.view?.window?.rootViewController?.dismissViewControllerAnimated(true, completion: {() in
                println("dismissed loginviewcontroller suceeded")
                self.view?.presentScene(ModeMenuScene(size: self.view!.bounds.size))
            })
        }
    }
}

It does print login succeeded but not dismissed loginviewcontroller succeeded. How can I dismiss the loginview upon login and go back to my LoginScene ?

2

There are 2 answers

0
Kalzem On BEST ANSWER

Found the solution : I need to make use of the first parameter instead of relying on the delegate controller.

func logInViewController(logInController: PFLogInViewController!, didLogInUser user: PFUser!) {
    logInController.dismissViewControllerAnimated(true, completion: {() in
        self.view?.presentScene(GameScene(size: self.view!.bounds.size))  //Go to Game Scene
        return
    })
}
1
Eric Nakagawa - Parse Dev Adv On

This question isn't related to Parse. Instead I'd look into better handling the dismissViewControllerAnimated() method.

Try switching:

self.view?.window?.rootViewController?.dismissViewControllerAnimated...

to

self.dismissViewControllerAnimated...