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
		
	
| 
											9 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											9 years ago
										 | // | ||
|  | 
 | ||
|  | import Foundation | ||
|  | 
 | ||
| 
											8 years ago
										 | @objc public class OWSAlerts: NSObject { | ||
| 
											9 years ago
										 | 
 | ||
|  |     /// Cleanup and present alert for no permissions | ||
| 
											8 years ago
										 |     @objc | ||
| 
											9 years ago
										 |     public class func showNoMicrophonePermissionAlert() { | ||
| 
											8 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") | ||
| 
											7 years ago
										 |         let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert) | ||
| 
											8 years ago
										 | 
 | ||
| 
											7 years ago
										 |         let dismissAction = UIAlertAction(title: CommonStrings.dismissButton, style: .cancel) | ||
|  |         dismissAction.accessibilityIdentifier = "OWSAlerts.\("dismiss")" | ||
| 
											7 years ago
										 |         alert.addAction(dismissAction) | ||
| 
											7 years ago
										 | 
 | ||
| 
											8 years ago
										 |         if let settingsAction = CurrentAppContext().openSystemSettingsAction { | ||
| 
											7 years ago
										 |             settingsAction.accessibilityIdentifier = "OWSAlerts.\("settings")" | ||
| 
											7 years ago
										 |             alert.addAction(settingsAction) | ||
| 
											8 years ago
										 |         } | ||
| 
											7 years ago
										 |         CurrentAppContext().frontmostViewController()?.presentAlert(alert) | ||
| 
											9 years ago
										 |     } | ||
| 
											9 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 | ||
|  |         } | ||
| 
											7 years ago
										 |         frontmostViewController.presentAlert(alert) | ||
| 
											7 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc | ||
| 
											8 years ago
										 |     public class func showAlert(title: String) { | ||
|  |         self.showAlert(title: title, message: nil, buttonTitle: nil) | ||
| 
											9 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc | ||
| 
											8 years ago
										 |     public class func showAlert(title: String?, message: String) { | ||
|  |         self.showAlert(title: title, message: message, buttonTitle: nil) | ||
| 
											9 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc | ||
| 
											8 years ago
										 |     public class func showAlert(title: String?, message: String? = nil, buttonTitle: String? = nil, buttonAction: ((UIAlertAction) -> Void)? = nil) { | ||
| 
											8 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?) { | ||
| 
											9 years ago
										 | 
 | ||
| 
											9 years ago
										 |         let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | ||
| 
											7 years ago
										 | 
 | ||
|  |         let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "") | ||
|  |         let okAction = UIAlertAction(title: actionTitle, style: .default, handler: buttonAction) | ||
|  |         okAction.accessibilityIdentifier = "OWSAlerts.\("ok")" | ||
|  |         alert.addAction(okAction) | ||
| 
											7 years ago
										 |         fromViewController?.presentAlert(alert) | ||
| 
											9 years ago
										 |     } | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |     @objc | ||
| 
											8 years ago
										 |     public class func showConfirmationAlert(title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) { | ||
| 
											8 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: "") | ||
| 
											7 years ago
										 |         let okAction = UIAlertAction(title: actionTitle, style: .default, handler: proceedAction) | ||
|  |         okAction.accessibilityIdentifier = "OWSAlerts.\("ok")" | ||
|  |         alert.addAction(okAction) | ||
| 
											8 years ago
										 | 
 | ||
| 
											7 years ago
										 |         CurrentAppContext().frontmostViewController()?.presentAlert(alert) | ||
| 
											8 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc | ||
| 
											8 years ago
										 |     public class func showErrorAlert(message: String) { | ||
| 
											8 years ago
										 |         self.showAlert(title: CommonStrings.errorAlertTitle, message: message, buttonTitle: nil) | ||
| 
											8 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 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. | ||
|  |         } | ||
| 
											7 years ago
										 |         action.accessibilityIdentifier = "OWSAlerts.\("cancel")" | ||
| 
											8 years ago
										 |         return action | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc | ||
|  |     public class func showIOSUpgradeNagIfNecessary() { | ||
| 
											7 years ago
										 |         // Our min SDK is iOS9, so this will only show for iOS9 users | ||
|  |         if #available(iOS 10.0, *) { | ||
| 
											8 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 { | ||
| 
											8 years ago
										 |             return | ||
|  |         } | ||
|  | 
 | ||
| 
											7 years ago
										 |         if let iOSUpgradeNagDate = Environment.shared.preferences.iOSUpgradeNagDate() { | ||
| 
											7 years ago
										 |             let kNagFrequencySeconds = 14 * kDayInterval | ||
| 
											8 years ago
										 |             guard fabs(iOSUpgradeNagDate.timeIntervalSinceNow) > kNagFrequencySeconds else { | ||
|  |                 return | ||
|  |             } | ||
|  |         } | ||
|  | 
 | ||
| 
											7 years ago
										 |         Environment.shared.preferences.setIOSUpgradeNagDate(Date()) | ||
| 
											8 years ago
										 | 
 | ||
| 
											8 years ago
										 |         OWSAlerts.showAlert(title: NSLocalizedString("UPGRADE_IOS_ALERT_TITLE", | ||
| 
											8 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.")) | ||
| 
											8 years ago
										 |     } | ||
| 
											9 years ago
										 | } |