2017-03-02 21:11:44 +01:00
|
|
|
//
|
2019-03-30 14:24:40 +01:00
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
2017-03-02 21:11:44 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2018-05-25 22:51:40 +02:00
|
|
|
@objc public extension UIApplication {
|
2017-03-02 21:11:44 +01:00
|
|
|
|
2019-03-30 14:24:40 +01:00
|
|
|
public var frontmostViewControllerIgnoringAlerts: UIViewController? {
|
2018-04-16 23:19:06 +02:00
|
|
|
return findFrontmostViewController(ignoringAlerts: true)
|
2017-09-12 23:14:43 +02:00
|
|
|
}
|
|
|
|
|
2019-03-30 14:24:40 +01:00
|
|
|
public var frontmostViewController: UIViewController? {
|
2018-04-16 23:19:06 +02:00
|
|
|
return findFrontmostViewController(ignoringAlerts: false)
|
2017-09-12 23:14:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
internal func findFrontmostViewController(ignoringAlerts: Bool) -> UIViewController? {
|
2018-04-16 23:19:06 +02:00
|
|
|
guard let window = CurrentAppContext().mainWindow else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
Logger.error("findFrontmostViewController: \(window)")
|
|
|
|
guard let viewController = window.rootViewController else {
|
2018-08-27 16:27:48 +02:00
|
|
|
owsFailDebug("Missing root view controller.")
|
2017-12-04 16:35:47 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return viewController.findFrontmostViewController(ignoringAlerts)
|
2017-03-02 21:11:44 +01:00
|
|
|
}
|
|
|
|
|
2019-03-30 14:24:40 +01:00
|
|
|
public func openSystemSettings() {
|
2019-03-30 14:22:31 +01:00
|
|
|
openURL(URL(string: UIApplication.openSettingsURLString)!)
|
2017-05-05 18:39:21 +02:00
|
|
|
}
|
|
|
|
|
2017-03-02 21:11:44 +01:00
|
|
|
}
|