mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
5.1 KiB
Swift
125 lines
5.1 KiB
Swift
8 years ago
|
//
|
||
6 years ago
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||
8 years ago
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
7 years ago
|
@objc public class OWSAlerts: NSObject {
|
||
8 years ago
|
|
||
|
/// Cleanup and present alert for no permissions
|
||
7 years ago
|
@objc
|
||
8 years ago
|
public class func showNoMicrophonePermissionAlert() {
|
||
7 years ago
|
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")
|
||
6 years ago
|
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
|
||
7 years ago
|
|
||
6 years ago
|
let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel)
|
||
|
dismissAction.accessibilityIdentifier = "OWSAlerts.\("dismiss")"
|
||
6 years ago
|
alert.addAction(dismissAction)
|
||
6 years ago
|
|
||
7 years ago
|
if let settingsAction = CurrentAppContext().openSystemSettingsAction {
|
||
6 years ago
|
settingsAction.accessibilityIdentifier = "OWSAlerts.\("settings")"
|
||
6 years ago
|
alert.addAction(settingsAction)
|
||
7 years ago
|
}
|
||
6 years ago
|
CurrentAppContext().frontmostViewController()?.presentAlert(alert)
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
@objc
|
||
|
public class func showAlert(_ alert: UIAlertController) {
|
||
|
guard let frontmostViewController = CurrentAppContext().frontmostViewController() else {
|
||
7 years ago
|
owsFailDebug("frontmostViewController was unexpectedly nil")
|
||
7 years ago
|
return
|
||
|
}
|
||
6 years ago
|
frontmostViewController.presentAlert(alert)
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
7 years ago
|
public class func showAlert(title: String) {
|
||
|
self.showAlert(title: title, message: nil, buttonTitle: nil)
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
7 years ago
|
public class func showAlert(title: String?, message: String) {
|
||
|
self.showAlert(title: title, message: message, buttonTitle: nil)
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
7 years ago
|
public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil) {
|
||
7 years ago
|
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?) {
|
||
8 years ago
|
|
||
8 years ago
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||
6 years ago
|
|
||
|
let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "")
|
||
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: buttonAction)
|
||
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
||
|
alert.addAction(okAction)
|
||
6 years ago
|
fromViewController?.presentAlert(alert)
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
@objc
|
||
7 years ago
|
public class func showConfirmationAlert(title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) {
|
||
7 years ago
|
assert(title.count > 0)
|
||
8 years ago
|
|
||
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||
|
alert.addAction(self.cancelAction)
|
||
|
|
||
|
let actionTitle = proceedTitle ?? NSLocalizedString("OK", comment: "")
|
||
6 years ago
|
let okAction = UIAlertAction(title: actionTitle, style: .default, handler: proceedAction)
|
||
|
okAction.accessibilityIdentifier = "OWSAlerts.\("ok")"
|
||
|
alert.addAction(okAction)
|
||
8 years ago
|
|
||
6 years ago
|
CurrentAppContext().frontmostViewController()?.presentAlert(alert)
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
7 years ago
|
public class func showErrorAlert(message: String) {
|
||
7 years ago
|
self.showAlert(title: CommonStrings.errorAlertTitle, message: message, buttonTitle: nil)
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
8 years ago
|
public class var cancelAction: UIAlertAction {
|
||
8 years ago
|
let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in
|
||
8 years ago
|
Logger.debug("Cancel item")
|
||
|
// Do nothing.
|
||
|
}
|
||
6 years ago
|
action.accessibilityIdentifier = "OWSAlerts.\("cancel")"
|
||
8 years ago
|
return action
|
||
|
}
|
||
|
|
||
7 years ago
|
@objc
|
||
|
public class func showIOSUpgradeNagIfNecessary() {
|
||
6 years ago
|
// Our min SDK is iOS9, so this will only show for iOS9 users
|
||
|
if #available(iOS 10.0, *) {
|
||
7 years ago
|
return
|
||
|
}
|
||
|
|
||
|
// Don't show the nag to users who have just launched
|
||
|
// the app for the first time.
|
||
7 years ago
|
guard AppVersion.sharedInstance().lastAppVersion != nil else {
|
||
7 years ago
|
return
|
||
|
}
|
||
|
|
||
7 years ago
|
if let iOSUpgradeNagDate = Environment.shared.preferences.iOSUpgradeNagDate() {
|
||
6 years ago
|
let kNagFrequencySeconds = 14 * kDayInterval
|
||
7 years ago
|
guard fabs(iOSUpgradeNagDate.timeIntervalSinceNow) > kNagFrequencySeconds else {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
Environment.shared.preferences.setIOSUpgradeNagDate(Date())
|
||
7 years ago
|
|
||
7 years ago
|
OWSAlerts.showAlert(title: NSLocalizedString("UPGRADE_IOS_ALERT_TITLE",
|
||
7 years ago
|
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."))
|
||
7 years ago
|
}
|
||
8 years ago
|
}
|