【问题标题】:How to dismiss message app in swift?如何快速关闭消息应用程序?
【发布时间】:2018-12-20 04:57:11
【问题描述】:

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

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

所以如果应用确实进入了后台,请请求密码。

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

但是,具体的情况很奇怪。

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. 密码视图如何覆盖 MFMessageComposeViewController?

  2. 或如何关闭 MFMessageComposeViewController?

最好的方法是什么???

【问题讨论】:

标签: ios swift uiwindow


【解决方案1】:

您需要迭代您的应用程序呈现的 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)

}

【讨论】:

  • 你看到我的视频了吗??我无法创建 MFMessageComposeViewController。因为它是由苹果的框架消息应用程序自动创建的。如果你不明白我的回复,你应该看看我的视频。
  • 我看了你的视频。你能分享你触发消息应用程序的代码吗?
  • 只是活动控制器是触发器。像这样。
  • let message = "string..." let actController = UIActivityViewController(activityItems: [message], applicationActivities: nil) self.present(actController, animated: true, completion: nil)
  • 检查我修改后的答案
猜你喜欢
  • 1970-01-01
  • 2017-02-10
  • 2021-09-11
  • 1970-01-01
  • 2012-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多