gpt4 book ai didi

ios - 退出 UIViewController 时禁用 "Save Password"操作表?

转载 作者:行者123 更新时间:2023-12-04 11:26:58 26 4
gpt4 key购买 nike

我的应用程序有一个“创建帐户” View Controller (如下所示),提示用户输入用户名和密码。每当我转到另一个 View Controller 时,都会弹出一个操作表,提示将密码保存在钥匙串(keychain)中。

如果用户成功创建新帐户,这是一个漂亮的小免费赠品。但是,如果用户点击导航栏中的取消(后退)按钮,如果他们选择使用 Facebook 登录而不是创建帐户的选项,或任何其他离开此 View Controller 的方式,我都会收到相同的弹出窗口(见图以下)。

我怎样才能让这个弹出窗口只在用户成功创建新帐户时显示?

编辑 :根据请求,这里是与导致“保存密码”操作表出现的 segue 相关的代码。

来自 CreateAccountViewController.swift:

class CreateAccountViewController : UIViewController
{
// ... bunch of irrelevant code deleted ...

// bound to "Connect with Facebook" button (see image below)
@IBAction func switchToFacebook(_ sender : UIButton)
{
performSegue(.SwitchToFacebookLogin, sender: sender)
}
// ... bunch of irrelevant code deleted ...
}

extension CreateAccountViewController : GameServerAlertObserver
{
// callback based on response from GameCenter after
// submitting a "create new user" request
func handleConnectionResponse(_ response:GameServerResponse )
{
switch response
{
// ... other response cases removed ...
case .UserCreated:
self.removeSpinner()
performSegue(.CreateAccountToStartup, sender: self)

default:
response.displayAlert(over: self, observer: self)
self.removeSpinner()
}
}

// Functions defined in the GameServerAlertObserver protocol
// to handle user response to "User Exists Popup" (figure below)
func ok()
{
// user chose to enter new password... clear the existing username field
usernameTextField.text = ""
}

func cancel()
{
// segue back to the startup view controller
performSegue(.CreateAccountToStartup, sender: self)
}

func goToLogin()
{
// segue to the login view controller
performSegue(.SwitchToAccountLogin, sender:self)
}
}

来自 UIViewController_Segues:
enum SegueIdentifier : String
{
case LoserBoard = "loserBoard"
case CreateAccount = "createAccount"
case AccountLogin = "accountLogin"
case FacebookLogin = "facebookLogin"
case SwitchToFacebookLogin = "switchToFacebookLogin"
case SwitchToAccountLogin = "switchToAccountLogin"
case CreateAccountToStartup = "createAccountToStartup"
case AccountLoginToStartup = "accountLoginToStartup"
case FacebookLoginToStartup = "facebookLoginToStartup"
case UnwindToStartup = "unwindToStartup"
}

extension UIViewController
{
func performSegue(_ target:SegueIdentifier, sender:Any?)
{
performSegue(withIdentifier: target.rawValue, sender: sender)
}
}

来自 GameServerAlert.swift:
protocol GameServerAlertObserver
{
func ok()
func cancel()
func goToLogin()
}

extension GameServerResponse
{
func displayAlert(over controller:UIViewController, observer:GameServerAlertObserver? = nil)
{
var title : String
var message : String
var actions : [UIAlertAction]

switch self
{
// ... deleted cases/default which don't lead to segue ...

case .UserAlreadyExists:
title = "User already exists"
message = "\nIf this is you, please use the login page to reconnect.\n\nIf this is not you, you will need to select a different username."
actions = [
UIAlertAction(title: "Go to Login page", style: .default, handler: { _ in observer?.goToLogin() } ),
UIAlertAction(title: "Enter new username", style: .default, handler: { _ in observer?.ok() } ),
UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in observer?.cancel() } )
]
}

let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
actions.forEach { (action) in alert.addAction(action) }
controller.present(alert,animated:true)
}
}

模拟器中的例子:

创建帐户 - (用户在此处输入新帐户的用户名和密码。)

enter image description here

Facebook 登录

如果用户决定使用 Facebook 登录而不是创建用户帐户,他们将被带到这个 View (我还没有充实)。请注意,“保存密码”操作表已弹出。

enter image description here

用户存在弹出

如果用户尝试使用已存在的用户名创建帐户,他们将看到此弹出窗口。如果他们选择取消,他们将返回到启动屏幕(见下文)。如果他们选择输入新用户名,他们将保留在同一个屏幕上并清除用户名。如果他们选择登录,他们将被带到登录屏幕。

enter image description here

开机画面

如果用户选择上面的取消,他们将被带回这里。再次注意,“保存密码”操作表已弹出。

enter image description here

最佳答案

当用户执行以下操作时,我如何避免自动保存密码操作表:

  • 关闭登录 View Controller ;
  • 弹出 View Controller ;
  • 使用交互式流行手势。

  • =>
      override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    passwordTextField.textContentType = .password
    }
    }

    override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    if isMovingFromParent || isBeingDismissed || parent?.isBeingDismissed == true {
    passwordTextField.textContentType = nil
    }
    }

    关于ios - 退出 UIViewController 时禁用 "Save Password"操作表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60804377/

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