0
我试图避免整个开始/登录屏幕,并直接进入应用程序的第一页,如果用户登录。当我运行下面的代码没有什么反应。我突出了点,它表示当前用户是零,但是当视图加载时,当前用户不是零。如何使用PFUser更改初始视图控制器?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
var currentUser = PFUser.currentUser()
print("user \(currentUser)")
if currentUser != nil {
if(currentUser?.username?.rangeOfString("@music.co") != nil){
self.storyboard?.instantiateViewControllerWithIdentifier("venuehomescreen")
}else{
self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("userhomescreen")
}
}
}
这就是我现在正在做的,但我不希望用户总是单击登录按钮来执行segue。而是在加载屏幕后自动进入主屏幕。 – user6032625
但是如果它在viewDidAppear中的初始视图控制器到您的应用程序(登录视图控制器),它不需要你的用户。如果有人缓存,应用程序将继续登录用户 –
是的,这是发生了什么,但我看到登录页面,然后进入主屏幕,是否有避免这种情况? – user6032625