ios - 如何快速关闭消息应用程序?

标签 ios swift uiwindow

你能在这里看到吗:https://vimeo.com/279403383

我正在尝试显示密码 View 。因为这个应用程序对安全性很敏感。

因此,如果应用程序确实进入后台,则请求密码。

在这种情况下工作得很好。

但是,具体情况的工作方式很奇怪。

func applicationDidEnterBackground(_ application: UIApplication) {
            guard let passcodeManageView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "passcodeManageView") as? PasscodeManageViewController else { return }
            passcodeManageView.state = State.loginMode
            passcodeManageView.modalPresentationStyle = .overFullScreen

            var rootViewController = UIApplication.shared.keyWindow?.rootViewController
            while let presentController = rootViewController?.presentedViewController {
                rootViewController = presentController
            }
            rootViewController?.present(passcodeManageView, animated: false, completion: nil)
    }

所以,我的问题是

  1. 密码 View 如何覆盖MFMessageComposeViewController?

  2. 或者如何关闭 MFMessageComposeViewController?

最好的方法是什么???

最佳答案

您需要迭代应用程序中呈现的 ViewController 并 将它们一一关闭。

func applicationDidEnterBackground(_ application: UIApplication) {  
    if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
      var  presented = rootViewController.presentedViewController
      while presented != nil
      {
        if presented is MFMessageComposeViewController {
          rootViewController.dismiss(animated: false, completion: nil)
          break
        } else {
           presented = presented?.presentedViewController
        }
      }

    }

    guard let passcodeManageView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "passcodeManageView") as? PasscodeManageViewController else { return }
    passcodeManageView.state = State.loginMode
    passcodeManageView.modalPresentationStyle = .overFullScreen

    var rootViewController = UIApplication.shared.keyWindow?.rootViewController
    while let presentController = rootViewController?.presentedViewController {
      rootViewController = presentController
    }
    rootViewController?.present(passcodeManageView, animated: false, completion: nil)

}

关于ios - 如何快速关闭消息应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51297534/

相关文章:

ios - 初始化方法的参数具有默认值时的问题

objective-c - TTPickerTextField 示例

iphone - 将 UIView 或 UIWindow 放置在 Statusbar 上方

swift - 更改分组的 UITableView 页脚文本标签颜色

swift - 在 Swift 协议(protocol)中约束关联类型

iphone - makeKeyAndVisible & makeKeyWindow - iPhone 中的 uiwindow

iphone - 如何在没有导航 Controller 的情况下使用多个 iOS 自定义 View Controller

ios - 如何居中 KC FloatingActionButton

ios - 未检测到 SpriteKit 碰撞

ios - 将项目升级到 Xcode 8