mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2024-12-25 02:52:35 +00:00
13b720442d
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
26 lines
1.1 KiB
Swift
26 lines
1.1 KiB
Swift
// SPDX-License-Identifier: MIT
|
|
// Copyright © 2018-2021 WireGuard LLC. All Rights Reserved.
|
|
|
|
import UIKit
|
|
|
|
class ConfirmationAlertPresenter {
|
|
static func showConfirmationAlert(message: String, buttonTitle: String, from sourceObject: AnyObject, presentingVC: UIViewController, onConfirmed: @escaping (() -> Void)) {
|
|
let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in
|
|
onConfirmed()
|
|
}
|
|
let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel)
|
|
let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet)
|
|
alert.addAction(destroyAction)
|
|
alert.addAction(cancelAction)
|
|
|
|
if let sourceView = sourceObject as? UIView {
|
|
alert.popoverPresentationController?.sourceView = sourceView
|
|
alert.popoverPresentationController?.sourceRect = sourceView.bounds
|
|
} else if let sourceBarButtonItem = sourceObject as? UIBarButtonItem {
|
|
alert.popoverPresentationController?.barButtonItem = sourceBarButtonItem
|
|
}
|
|
|
|
presentingVC.present(alert, animated: true, completion: nil)
|
|
}
|
|
}
|