From 540f57dfd52184ae3b0a9664f716cdb025abd471 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Mon, 20 Nov 2023 11:49:25 -0500 Subject: [PATCH] Fix #8446: Use correct `select` method on BVC when opening URLs (#8447) A crash was introduced in https://github.com/brave/brave-ios/pull/8306 due to accidentally calling the Obj-C `select(_ sender:)` method on UIResponder instead of `select(url:)`. --- .../Brave/Frontend/Browser/BrowserViewController.swift | 9 +++++++++ .../BrowserViewController+BraveTalk.swift | 2 +- Sources/Brave/Shortcuts/ActivityShortcutManager.swift | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index d724f3fd12b..0c4e0c93b58 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -2979,6 +2979,15 @@ extension BrowserViewController: ToolbarUrlActionsDelegate { self.tabManager.addTabsForURLs(urls, zombie: false, isPrivate: tabIsPrivate) } +#if DEBUG + public override func select(_ sender: Any?) { + if sender is URL { + assertionFailure("Wrong method called, use `select(url:)` or `select(_:action:)`") + } + super.select(sender) + } +#endif + func select(url: URL) { select(url, action: .openInCurrentTab) } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift index 329af376b77..01ee8a59e28 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift @@ -26,7 +26,7 @@ extension BrowserViewController { var components = URLComponents() components.host = currentHost components.scheme = url.scheme - self.select(components.url!) + self.select(url: components.url!) } } ) diff --git a/Sources/Brave/Shortcuts/ActivityShortcutManager.swift b/Sources/Brave/Shortcuts/ActivityShortcutManager.swift index 4b9238c1c1c..77cb9e534c5 100644 --- a/Sources/Brave/Shortcuts/ActivityShortcutManager.swift +++ b/Sources/Brave/Shortcuts/ActivityShortcutManager.swift @@ -192,7 +192,7 @@ public class ActivityShortcutManager: NSObject { } else { let controller = NewsSettingsViewController(dataSource: bvc.feedDataSource, openURL: { url in bvc.dismiss(animated: true) - bvc.select(url) + bvc.select(url: url) }) controller.viewDidDisappear = { if Preferences.Review.braveNewsCriteriaPassed.value {