0

Can you see that here : https://vimeo.com/279403383

I'm trying present a passcode view. Because this app is sensitive to security.

So if app did enter background, request passcode.

In this case pretty well work.

But, specific case work oddly.

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

So, my question is

  1. How does passcode view cover MFMessageComposeViewController?

  2. or How to dismiss MFMessageComposeViewController?

What is the best way???

  • To dismiss any (modal) view controller, see https://stackoverflow.com/questions/33520899/single-function-to-dismiss-all-open-view-controllers – Andreas Oetjen Jul 12 '18 at 06:44

1 Answers1

0

You need to iterate the presented ViewControllers of your app and close them one by one.

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)

}
Christian Abella
  • 5,439
  • 2
  • 26
  • 39
  • You see my video?? I can't create MFMessageComposeViewController. Because it's automatic create by apple's framework message app. If you does not understand my reply, you should see my video. –  Jul 12 '18 at 05:11
  • I watched your video. Can you share the code where you trigger the message app? – Christian Abella Jul 12 '18 at 05:36
  • just activity controller is trigger. like this. –  Jul 12 '18 at 05:38
  • let message = "string..." let actController = UIActivityViewController(activityItems: [message], applicationActivities: nil) self.present(actController, animated: true, completion: nil) –  Jul 12 '18 at 05:39
  • check my modified answer – Christian Abella Jul 12 '18 at 05:55
  • I'll check this. –  Jul 12 '18 at 06:19
  • your modified answer is working that case. but I don't want whole presented view dismiss...just dismiss MFMessageComposeViewController... –  Jul 12 '18 at 06:50
  • What you need is simple if you are able to dismiss all the presented views. Just check for the `MFMessageComposerViewController` class and only dismiss that view – The iOSDev Jul 12 '18 at 09:57
  • I see your answer. your answer dismiss MFMessageViewController. So, Where should I write present passcode view?? –  Jul 12 '18 at 11:19
  • just add your existing code after the MFMessageViewController been dismissed. see updated answer. – Christian Abella Jul 13 '18 at 00:17