Skip to content

Commit

Permalink
修复iPad不弹窗的BUG,修复消息列表中由于iOS18 UIKit BUG导致的闪退
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Oct 8, 2024
1 parent 50d4010 commit bce1375
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Bark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

private func notificatonHandler(userInfo: [AnyHashable: Any]) {
let navigationController = Client.shared.currentNavigationController
let viewController = Client.shared.currentSnackbarController
func presentController() {
let alert = (userInfo["aps"] as? [String: Any])?["alert"] as? [String: Any]
let title = alert?["title"] as? String
Expand Down Expand Up @@ -182,17 +182,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if let url = url {
items.append(url)
}
let controller = UIApplication.shared.keyWindow?.rootViewController
let controller = Client.shared.window?.rootViewController
let activityController = UIActivityViewController(activityItems: items,
applicationActivities: nil)
controller?.present(activityController, animated: true, completion: 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) {
presentController()
}
Expand Down
24 changes: 15 additions & 9 deletions Common/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@ class Client: NSObject {
super.init()
}

var currentNavigationController: UINavigationController? {
// TODO: iPad 取值不对
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
return nav
var window: UIWindow? {
return UIApplication.shared.delegate?.window ?? nil
}

var currentSnackbarController: BarkSnackbarController? {
return self.window?.rootViewController as? BarkSnackbarController
}

var currentTabBarController: StateStorageTabBarController? {
// TODO: iPad 取值不对
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
return controller?.rootViewController as? StateStorageTabBarController
guard let snackbarController = self.currentSnackbarController else {
return nil
}
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
return (snackbarController.rootViewController as? BarkSplitViewController)?.compactController
} else {
return snackbarController.rootViewController as? BarkTabBarController
}
}

let appVersion: String = {
Expand Down Expand Up @@ -67,7 +73,7 @@ class Client: NSObject {
UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true]) { success in
if !success {
// 打不开Universal Link时,则用内置 safari 打开
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
self.currentSnackbarController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
}
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions Controller/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import Material
import UIKit

class BaseViewController<T>: UIViewController where T: ViewModel {
let viewModel: T
init(viewModel: T) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)

self.view.backgroundColor = BKColor.background.primary
}

@available(*, unavailable)
Expand All @@ -28,6 +27,8 @@ class BaseViewController<T>: UIViewController where T: ViewModel {

override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = BKColor.background.primary

if UIDevice.current.userInterfaceIdiom == .pad {
navigationItem.largeTitleDisplayMode = .never
} else {
Expand Down
4 changes: 1 addition & 3 deletions Controller/MessageListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ class MessageListViewController: BaseViewController<MessageListViewModel> {
}

private func scrollToTop() {
if self.tableView.visibleCells.count > 0 {
self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
}
self.tableView.setContentOffset(CGPoint(x: 0, y: -250), animated: false)
}
}

Expand Down

0 comments on commit bce1375

Please sign in to comment.