gpt4 book ai didi

ios - 当新用户使用 Swift 和 Parse 登录时,数据不会更新到当前用户

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:19 25 4
gpt4 key购买 nike

我正在开发一个使用电话号码和短信验证登录的应用程序。除了一个小问题外,一切都很好。如果我注销一个用户,然后用另一个用户登录,则会加载以前的用户数据,但是会创建一个新用户,但会显示以前的用户数据。我必须注销并再次登录新用户才能加载他们的数据。有人看到发生了什么事吗?

登录码:

class LoginViewController: UIViewController {

func displayAlert(title: String, message: String) {
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
}))
self.presentViewController(alert, animated: true, completion: nil)
}


@IBOutlet weak var instructionLabel: UILabel!
@IBOutlet weak var phoneNumberTextField: UITextField!
@IBOutlet weak var sendCodeButton: UIButton!

var phoneNumber: String = ""



override func viewDidLoad() {
super.viewDidLoad()

first()
self.editing = true
}

func first() {
phoneNumber = ""
phoneNumberTextField.placeholder = "555-555-5555"
instructionLabel.text = "Enter your phone number to login or sign up"
sendCodeButton.enabled = true
}

func second() {

phoneNumber = phoneNumberTextField.text!
phoneNumberTextField.text = ""
phoneNumberTextField.placeholder = "1234"
instructionLabel.text = "Enter your 4 digit security code"
sendCodeButton.enabled = true
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

phoneNumberTextField.becomeFirstResponder()
}

@IBAction func didTapSendCodeButton() {

let preferredLanguage = NSBundle.mainBundle().preferredLocalizations[0]

let textFieldText = phoneNumberTextField.text ?? ""

if phoneNumber == "" {
if (preferredLanguage == "en" && textFieldText.characters.count != 10) {
displayAlert("Phone Login", message: NSLocalizedString("warningphone", comment: "You must enter a 10 digit US phone number including area code"))
return first()
}

self.editing = false
let params = ["phoneNumber" : textFieldText, "language" : preferredLanguage]
PFCloud.callFunctionInBackground("sendCode", withParameters: params) { response, error in
self.editing = true
if let error = error {
var description = error.description
if description.characters.count == 0 {
description = NSLocalizedString("warningGeneral", comment: "Something went Wrong. Please try again")
} else if let message = error.userInfo["error"] as? String {
description = message
}
self.displayAlert("Login Error", message: description)
return self.first()
}
return self.second()
}
} else {
if textFieldText.characters.count == 4, let code = Int(textFieldText) {
return doLogin(phoneNumber, code: code)
}

displayAlert("Code Entry", message: NSLocalizedString("warningCodeLength", comment: "You must enter the 4 digit code texted to your number"))
}
}

func doLogin(phoneNumber: String, code: Int) {

self.editing = false
let params = ["phoneNumber": phoneNumber, "codeEntry": code] as [NSObject:AnyObject]
PFCloud.callFunctionInBackground("logIn", withParameters: params) { response, error in
if let description = error?.description {
self.editing = true
return self.displayAlert("Login Error", message: description)
}
if let token = response as? String {
PFUser.becomeInBackground(token) { user, error in
if let _ = error{
self.displayAlert("Login Error", message: NSLocalizedString("warningGeneral", comment: "Something happened while logging in. Please try again"))
self.editing = true
return self.first()
}

return self.dismissViewControllerAnimated(true, completion: nil)
}
} else {
self.editing = true
self.displayAlert("Login Error", message: NSLocalizedString("warningGeneral", comment: "Something went wrong. Please try again"))
return self.first()
}
}
}

override func setEditing(editing: Bool, animated: Bool) {
sendCodeButton.enabled = editing
phoneNumberTextField.enabled = editing
if editing {
phoneNumberTextField.becomeFirstResponder()
}
}
}

extension LoginViewController : UITextFieldDelegate {
func textFieldShouldReturn(textField: UITextField) -> Bool {
self.didTapSendCodeButton()

return true

}
}

最佳答案

发现问题我必须更新 viewWillAppear 中的标签

关于ios - 当新用户使用 Swift 和 Parse 登录时,数据不会更新到当前用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34146125/

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