退出 UIViewController 时禁用 "Save Password" 操作 sheet?

Disable "Save Password" action sheet when exiting UIViewController?

我的应用程序有一个 "Create Account" 视图控制器(如下所示),提示用户输入用户名和密码。每当我转到另一个视图控制器时,我都会收到一个弹出操作 sheet 提示将密码保存在钥匙串中。

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

如何让这个弹出窗口仅在用户成功创建新帐户时显示?

编辑:根据请求,这里是与导致 "Save Password" 操作 sheet 出现的转场相关的代码。

来自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)
  }
}

来自模拟器的示例:

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

Facebook 登录

如果用户决定使用 Facebook 登录而不是创建用户帐户,他们将被带到这个视图(我还没有充实)。请注意,"Save Password" 操作 sheet 已弹出。

用户存在弹出窗口

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

启动画面

如果用户select在上面取消,他们会被带回这里。再次注意,"Save Password" 操作 sheet 已弹出。

在显示操作 sheet 的代码块 运行 之前添加一个条件。您只需使用 if 语句即可完成此操作。该语句必须检查帐户是否已成功创建。显示操作 sheet 的代码块必须 运行 仅当条件为真时。

抱歉,我的回答很简短,我通常 post 不在这个网站上。这是关闭创建用户屏幕时在您的设备上自动填充的密码。

Apple 文档:https://developer.apple.com/documentation/security/password_autofill

这是一个很好地满足了所有要求的网站 link:https://developerinsider.co/ios12-password-autofill-automatic-strong-password-and-security-code-autofill/

当用户 :

时,我如何避免自动 保存密码 操作 sheet
  • 关闭登录视图控制器;
  • 弹出视图控制器;
  • 使用交互式弹出手势。

=>

  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
    }
  }