gpt4 book ai didi

swift - 如果数据库中存在匿名用户,则转至主屏幕

转载 作者:行者123 更新时间:2023-11-30 14:05:35 25 4
gpt4 key购买 nike

我正在使用PFAnonymousUtilsPFUser.enableAutomaticUser。我想检查用户是否存在是数据库,如果是的话我想转向 DiscoverViewController。

问题是,即使没有用户,应用程序也会继续转发到 DiscoverVc...

    let currentUser = PFUser.currentUser()

if currentUser != nil {

let storyboard = UIStoryboard(name: "Main", bundle: nil)

// instantiate your desired ViewController
let rootController = storyboard.instantiateViewControllerWithIdentifier("DiscoverVc")

// Because self.window is an optional you should check it's value first and assign your rootViewController
if self.window != nil {
self.window!.rootViewController = rootController
}

} else {

let installation = (PFInstallation.currentInstallation())
installation["User"] = PFUser.currentUser()
installation.saveInBackground()

PFAnonymousUtils.logInWithBlock {
(user: PFUser?, error: NSError?) -> Void in
if error != nil || user == nil {

print("Anonymous user failed")

} else {

print("Anonymous user logged in.")
}

}
}

最佳答案

来自解析文档:

PFUser.enableAutomaticUser

After calling this method, currentUser will always have a value. The user will only be created on the server once the user has been saved, or once an object with a relation to that user or an ACL that refers to the user has been saved.

要检查用户是否是匿名用户,请使用:

PFAnonymousUtils.isLinkedWithUser(PFUser.currentUser())

Return Value YES if the user is anonymous. NO if the user is not the current user or is not anonymous.

关于swift - 如果数据库中存在匿名用户,则转至主屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32455463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com