diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 68ce5048e..77ed515bb 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -157,7 +157,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc } catch { let alert = UIAlertController(title: "Session", message: "An error occurred.", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) - return present(alert, animated: true, completion: nil) + return presentAlert(alert) } let type = urlResourceValues.typeIdentifier ?? (kUTTypeData as String) guard urlResourceValues.isDirectory != true else { @@ -556,7 +556,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc })) } } - present(sheet, animated: true, completion: nil) + presentAlert(sheet) } func handleViewItemDoubleTapped(_ viewItem: ConversationViewItem) { @@ -691,7 +691,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc OpenGroupAPIV2.ban(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete() })) alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) - present(alert, animated: true, completion: nil) + presentAlert(alert) } func banAndDeleteAllMessages(_ viewItem: ConversationViewItem) { @@ -705,7 +705,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc OpenGroupAPIV2.banAndDeleteAllMessages(publicKey, from: openGroupV2.room, on: openGroupV2.server).retainUntilComplete() })) alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) - present(alert, animated: true, completion: nil) + presentAlert(alert) } func handleQuoteViewCancelButtonTapped() { diff --git a/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift b/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift index d6a47a02b..61ea8f12a 100644 --- a/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift +++ b/Session/Conversations/Views & Modals/JoinOpenGroupModal.swift @@ -66,7 +66,7 @@ final class JoinOpenGroupModal : Modal { guard let (room, server, publicKey) = OpenGroupManagerV2.parseV2OpenGroup(from: url) else { let alert = UIAlertController(title: "Couldn't Join", message: nil, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil)) - return presentingViewController!.present(alert, animated: true, completion: nil) + return presentingViewController!.presentAlert(alert) } presentingViewController!.dismiss(animated: true, completion: nil) Storage.shared.write { [presentingViewController = self.presentingViewController!] transaction in @@ -78,7 +78,7 @@ final class JoinOpenGroupModal : Modal { .catch(on: DispatchQueue.main) { error in let alert = UIAlertController(title: "Couldn't Join", message: error.localizedDescription, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil)) - presentingViewController.present(alert, animated: true, completion: nil) + presentingViewController.presentAlert(alert) } } } diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index 7918f24f8..6ea8fc636 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -348,7 +348,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv }) alert.addAction(UIAlertAction(title: NSLocalizedString("TXT_CANCEL_TITLE", comment: ""), style: .default) { _ in }) guard let self = self else { return } - self.present(alert, animated: true, completion: nil) + self.presentAlert(alert) } delete.backgroundColor = Colors.destructive diff --git a/Session/Onboarding/PNModeVC.swift b/Session/Onboarding/PNModeVC.swift index 56f2c9afd..6ecb61008 100644 --- a/Session/Onboarding/PNModeVC.swift +++ b/Session/Onboarding/PNModeVC.swift @@ -91,7 +91,7 @@ final class PNModeVC : BaseVC, OptionViewDelegate { let title = NSLocalizedString("vc_pn_mode_no_option_picked_modal_title", comment: "") let alert = UIAlertController(title: title, message: nil, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil)) - return present(alert, animated: true, completion: nil) + return presentAlert(alert) } UserDefaults.standard[.isUsingFullAPNs] = (selectedOptionView == apnsOptionView) TSAccountManager.sharedInstance().didRegister() diff --git a/Session/Settings/SettingsVC.swift b/Session/Settings/SettingsVC.swift index ef9b4e0e4..79a652762 100644 --- a/Session/Settings/SettingsVC.swift +++ b/Session/Settings/SettingsVC.swift @@ -392,7 +392,7 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate { let message = isMaxFileSizeExceeded ? "Please select a smaller photo and try again" : "Please check your internet connection and try again" let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_OK", comment: ""), style: .default, handler: nil)) - self?.present(alert, animated: true, completion: nil) + self?.presentAlert(alert) } } }, requiresSync: true) diff --git a/SessionShareExtension/ShareVC.swift b/SessionShareExtension/ShareVC.swift index 34716c706..0e50b683e 100644 --- a/SessionShareExtension/ShareVC.swift +++ b/SessionShareExtension/ShareVC.swift @@ -225,7 +225,7 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD alert.addAction(UIAlertAction(title: "BUTTON_OK".localized(), style: .default, handler: { _ in self.extensionContext!.cancelRequest(withError: error) })) - present(alert, animated: true, completion: nil) + presentAlert(alert) } // MARK: Attachment Prep diff --git a/SignalUtilitiesKit/Utilities/UIView+OWS.swift b/SignalUtilitiesKit/Utilities/UIView+OWS.swift index 2e02932ef..7c64c12ab 100644 --- a/SignalUtilitiesKit/Utilities/UIView+OWS.swift +++ b/SignalUtilitiesKit/Utilities/UIView+OWS.swift @@ -132,11 +132,12 @@ public extension UIView { @objc public extension UIViewController { - public func presentAlert(_ alert: UIAlertController) { + func presentAlert(_ alert: UIAlertController) { self.presentAlert(alert, animated: true) } - public func presentAlert(_ alert: UIAlertController, animated: Bool) { + func presentAlert(_ alert: UIAlertController, animated: Bool) { + setupForIPadIfNeeded(alert: alert) self.present(alert, animated: animated, completion: { @@ -144,7 +145,8 @@ public extension UIViewController { }) } - public func presentAlert(_ alert: UIAlertController, completion: @escaping (() -> Void)) { + func presentAlert(_ alert: UIAlertController, completion: @escaping (() -> Void)) { + setupForIPadIfNeeded(alert: alert) self.present(alert, animated: true, completion: { @@ -153,6 +155,14 @@ public extension UIViewController { completion() }) } + + private func setupForIPadIfNeeded(alert: UIAlertController) { + if UIDevice.current.isIPad { + alert.popoverPresentationController?.permittedArrowDirections = [] + alert.popoverPresentationController?.sourceView = self.view + alert.popoverPresentationController?.sourceRect = self.view.bounds + } + } } // MARK: -