Обнаруживать, когда UIAlertController отклоняется другим UIViewController

Начиная с iOS 8 и нового UIAlertController, в сценарии, где:

  • Представлен UIAlertController.
  • Баннер локального push-уведомления отображается сверху в виде UIWindow.
  • Пользователь нажимает на баннер, а затем переходит к другому UIViewController, и UIAlertController закрывается window.rootViewController ...

Есть ли способ обнаружить такое увольнение, которое не активируется ни одной из кнопок UIAlertAction?


person rcat24    schedule 17.02.2015    source источник


Ответы (1)


Чтобы избежать увольнения вашего UIAlertViewController новым UIViewController, мое решение: - Создать новый UIWindow с level = UIWindowALertLEvel +1 - добавить пустой rootViewController для этого UIWindow - Сделать UIWIndow keyWindow - показать alertController из rootViewController.

Таким образом, этот alertcontroller не будет отклонен другим контроллером представления.

Мой код:

func showSimpleAlertOverWindow(title: String, msg: String, okButtonTitle : String, animated : Bool) {
        CLWrapper.logDebug("show message <\(msg)>")

        let _alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
        _alertWindow.rootViewController = UIViewController()
        _alertWindow.windowLevel = UIWindowLevelAlert + 1
        _alertWindow.hidden = false

        let alert = UIAlertController(title: title ?? "", message: msg ?? "", preferredStyle: UIAlertControllerStyle.Alert)
        let okBtn = UIAlertAction(title: okButtonTitle ?? "", style: UIAlertActionStyle.Default) { (alertAction) -> Void in
            _alertWindow.resignKeyWindow()
            _alertWindow.hidden = true

        }

        alert.addAction(okBtn)

        _alertWindow.makeKeyWindow()
        _alertWindow.rootViewController!.presentViewController(alert, animated: animated, completion: nil)

    }
person Duyen-Hoa    schedule 15.12.2015