修复iPad不弹窗的BUG,修复消息列表中由于iOS18 UIKit BUG导致的闪退

This commit is contained in:
Fin 2024-10-08 14:23:55 +08:00
parent 50d40104a4
commit bce1375ac1
4 changed files with 23 additions and 18 deletions

View File

@ -137,7 +137,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
} }
private func notificatonHandler(userInfo: [AnyHashable: Any]) { private func notificatonHandler(userInfo: [AnyHashable: Any]) {
let navigationController = Client.shared.currentNavigationController let viewController = Client.shared.currentSnackbarController
func presentController() { func presentController() {
let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any] let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any]
let title = alert?["title"] as? String let title = alert?["title"] as? String
@ -182,17 +182,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if let url = url { if let url = url {
items.append(url) items.append(url)
} }
let controller = UIApplication.shared.keyWindow?.rootViewController let controller = Client.shared.window?.rootViewController
let activityController = UIActivityViewController(activityItems: items, let activityController = UIActivityViewController(activityItems: items,
applicationActivities: nil) applicationActivities: nil)
controller?.present(activityController, animated: true, completion: nil) controller?.present(activityController, animated: true, completion: nil)
})) }))
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil)) alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel"), style: .cancel, handler: nil))
navigationController?.present(alertController, animated: true, completion: nil) viewController?.present(alertController, animated: true, completion: nil)
} }
if let presentedController = navigationController?.presentedViewController { if let presentedController = viewController?.presentedViewController {
presentedController.dismiss(animated: false) { presentedController.dismiss(animated: false) {
presentController() presentController()
} }

View File

@ -17,17 +17,23 @@ class Client: NSObject {
super.init() super.init()
} }
var currentNavigationController: UINavigationController? { var window: UIWindow? {
// TODO: iPad return UIApplication.shared.delegate?.window ?? nil
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController }
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
return nav var currentSnackbarController: BarkSnackbarController? {
return self.window?.rootViewController as? BarkSnackbarController
} }
var currentTabBarController: StateStorageTabBarController? { var currentTabBarController: StateStorageTabBarController? {
// TODO: iPad guard let snackbarController = self.currentSnackbarController else {
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController return nil
return controller?.rootViewController as? StateStorageTabBarController }
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
return (snackbarController.rootViewController as? BarkSplitViewController)?.compactController
} else {
return snackbarController.rootViewController as? BarkTabBarController
}
} }
let appVersion: String = { let appVersion: String = {
@ -67,7 +73,7 @@ class Client: NSObject {
UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true]) { success in UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true]) { success in
if !success { if !success {
// Universal Link safari // Universal Link safari
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil) self.currentSnackbarController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
} }
} }
} else { } else {

View File

@ -8,13 +8,12 @@
import Material import Material
import UIKit import UIKit
class BaseViewController<T>: UIViewController where T: ViewModel { class BaseViewController<T>: UIViewController where T: ViewModel {
let viewModel: T let viewModel: T
init(viewModel: T) { init(viewModel: T) {
self.viewModel = viewModel self.viewModel = viewModel
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
self.view.backgroundColor = BKColor.background.primary
} }
@available(*, unavailable) @available(*, unavailable)
@ -28,6 +27,8 @@ class BaseViewController<T>: UIViewController where T: ViewModel {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
self.view.backgroundColor = BKColor.background.primary
if UIDevice.current.userInterfaceIdiom == .pad { if UIDevice.current.userInterfaceIdiom == .pad {
navigationItem.largeTitleDisplayMode = .never navigationItem.largeTitleDisplayMode = .never
} else { } else {

View File

@ -225,9 +225,7 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
} }
private func scrollToTop() { private func scrollToTop() {
if self.tableView.visibleCells.count > 0 { self.tableView.setContentOffset(CGPoint(x: 0, y: -250), animated: false)
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
}
} }
} }