2017-05-08 18:34:50 +02:00
|
|
|
//
|
2019-03-20 15:45:36 +01:00
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
2017-05-08 18:34:50 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc public class OWSAlerts: NSObject {
|
2017-05-08 18:34:50 +02:00
|
|
|
|
|
|
|
/// Cleanup and present alert for no permissions
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2017-05-08 18:34:50 +02:00
|
|
|
public class func showNoMicrophonePermissionAlert() {
|
2018-02-23 18:46:04 +01:00
|
|
|
let alertTitle = NSLocalizedString("CALL_AUDIO_PERMISSION_TITLE", comment: "Alert title when calling and permissions for microphone are missing")
|
|
|
|
let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment: "Alert message when calling and permissions for microphone are missing")
|
2019-03-21 15:26:38 +01:00
|
|
|
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
|
2018-02-06 17:32:09 +01:00
|
|
|
|
2019-03-20 15:45:36 +01:00
|
|
|
let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel)
|
|
|
|
dismissAction.accessibilityIdentifier = "OWSAlerts.\("dismiss")"
|
2019-03-21 15:26:38 +01:00
|
|
|
alert.addAction(dismissAction)
|
2019-03-20 15:45:36 +01:00
|
|
|
|
2018-02-06 17:32:09 +01:00
|
|
|
if let settingsAction = CurrentAppContext().openSystemSettingsAction {
|
2019-03-20 15:45:36 +01:00
|
|
|
settingsAction.accessibilityIdentifier = "OWSAlerts.\("settings")"
|
2019-03-21 15:26:38 +01:00
|
|
|
alert.addAction(settingsAction)
|
2018-02-06 17:32:09 +01:00
|
|
|
}
|
2019-03-21 15:26:38 +01:00
|
|
|
CurrentAppContext().frontmostViewController()?.presentAlert(alert)
|
2017-05-08 18:34:50 +02:00
|
|
|
}
|
2017-05-08 19:29:10 +02:00
|
|
|
|
2018-08-08 18:49:21 +02:00
|
|
|
@objc
|
|
|
|
public class func showAlert(_ alert: UIAlertController) {
|
|
|
|
guard let frontmostViewController = CurrentAppContext().frontmostViewController() else {
|
2018-08-27 16:27:48 +02:00
|
|
|
owsFailDebug("frontmostViewController was unexpectedly nil")
|
2018-08-08 18:49:21 +02:00
|
|
|
return
|
|
|
|
}
|
2019-03-21 15:26:38 +01:00
|
|
|
frontmostViewController.presentAlert(alert)
|
2018-08-08 18:49:21 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String) {
|
|
|
|
self.showAlert(title: title, message: nil, buttonTitle: nil)
|
2017-05-09 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String?, message: String) {
|
|
|
|
self.showAlert(title: title, message: message, buttonTitle: nil)
|
2017-05-08 19:29:10 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil) {
|
2018-04-16 23:39:13 +02:00
|
|
|
guard let fromViewController = CurrentAppContext().frontmostViewController() else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
showAlert(title: title, message: message, buttonTitle: buttonTitle, buttonAction: buttonAction,
|
|
|
|
fromViewController: fromViewController)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc
|
|
|
|
public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil, fromViewController: UIViewController?) {
|
2017-05-09 16:45:20 +02:00
|
|
|
|
2017-05-08 19:29:10 +02:00
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
2019-03-20 15:45:36 +01:00
|
|
|
|
|
|
|
let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "")
|
|
|
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: buttonAction)
|
|
|
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
|
|
|
alert.addAction(okAction)
|
2019-03-21 15:26:38 +01:00
|
|
|
fromViewController?.presentAlert(alert)
|
2017-05-08 19:29:10 +02:00
|
|
|
}
|
2017-08-21 22:58:26 +02:00
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2018-03-01 20:41:45 +01:00
|
|
|
public class func showConfirmationAlert(title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) {
|
2017-12-04 16:35:47 +01:00
|
|
|
assert(title.count > 0)
|
2017-09-29 21:51:06 +02:00
|
|
|
|
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
alert.addAction(self.cancelAction)
|
|
|
|
|
|
|
|
let actionTitle = proceedTitle ?? NSLocalizedString("OK", comment: "")
|
2019-03-20 15:45:36 +01:00
|
|
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: proceedAction)
|
|
|
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
|
|
|
alert.addAction(okAction)
|
2017-09-29 21:51:06 +02:00
|
|
|
|
2019-03-21 15:26:38 +01:00
|
|
|
CurrentAppContext().frontmostViewController()?.presentAlert(alert)
|
2017-09-29 21:51:06 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:29:25 +01:00
|
|
|
@objc
|
2018-03-14 14:02:44 +01:00
|
|
|
public class func showErrorAlert(message: String) {
|
2018-03-06 21:40:29 +01:00
|
|
|
self.showAlert(title: CommonStrings.errorAlertTitle, message: message, buttonTitle: nil)
|
2018-03-06 14:29:25 +01:00
|
|
|
}
|
|
|
|
|
2017-12-04 16:35:47 +01:00
|
|
|
@objc
|
2017-09-29 21:51:06 +02:00
|
|
|
public class var cancelAction: UIAlertAction {
|
2017-09-01 15:30:16 +02:00
|
|
|
let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in
|
2017-08-21 22:58:26 +02:00
|
|
|
Logger.debug("Cancel item")
|
|
|
|
// Do nothing.
|
|
|
|
}
|
2019-03-20 15:45:36 +01:00
|
|
|
action.accessibilityIdentifier = "OWSAlerts.\("cancel")"
|
2017-08-21 22:58:26 +02:00
|
|
|
return action
|
|
|
|
}
|
|
|
|
|
2018-02-13 21:00:25 +01:00
|
|
|
@objc
|
|
|
|
public class func showIOSUpgradeNagIfNecessary() {
|
2019-03-21 23:25:56 +01:00
|
|
|
// Our min SDK is iOS9, so this will only show for iOS9 users
|
|
|
|
if #available(iOS 10.0, *) {
|
2018-02-13 21:00:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't show the nag to users who have just launched
|
|
|
|
// the app for the first time.
|
2018-08-02 21:18:40 +02:00
|
|
|
guard AppVersion.sharedInstance().lastAppVersion != nil else {
|
2018-02-13 21:00:25 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-31 19:44:13 +02:00
|
|
|
if let iOSUpgradeNagDate = Environment.shared.preferences.iOSUpgradeNagDate() {
|
2019-03-21 23:25:56 +01:00
|
|
|
let kNagFrequencySeconds = 14 * kDayInterval
|
2018-02-13 21:00:25 +01:00
|
|
|
guard fabs(iOSUpgradeNagDate.timeIntervalSinceNow) > kNagFrequencySeconds else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 19:44:13 +02:00
|
|
|
Environment.shared.preferences.setIOSUpgradeNagDate(Date())
|
2018-02-13 21:00:25 +01:00
|
|
|
|
2018-03-01 20:41:45 +01:00
|
|
|
OWSAlerts.showAlert(title: NSLocalizedString("UPGRADE_IOS_ALERT_TITLE",
|
2018-02-23 18:46:04 +01:00
|
|
|
comment: "Title for the alert indicating that user should upgrade iOS."),
|
|
|
|
message: NSLocalizedString("UPGRADE_IOS_ALERT_MESSAGE",
|
|
|
|
comment: "Message for the alert indicating that user should upgrade iOS."))
|
2018-02-13 21:00:25 +01:00
|
|
|
}
|
2017-05-08 18:34:50 +02:00
|
|
|
}
|