From 593deaf6f6128db380e95e2d369fede818d57c0a Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sun, 9 Mar 2025 13:48:48 +0300 Subject: [PATCH] Fixed opening universal links --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/AppDelegate.swift | 22 -------------------- AutoCat/Controllers/RecordsController.swift | 23 +-------------------- AutoCat/SceneDelegate.swift | 12 +++++++---- 4 files changed, 11 insertions(+), 50 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 121a70c..5555cb9 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -1785,7 +1785,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 151; + CURRENT_PROJECT_VERSION = 152; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; @@ -1812,7 +1812,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 151; + CURRENT_PROJECT_VERSION = 152; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index c4847c9..b17ee6b 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -3,19 +3,9 @@ import RealmSwift import PKHUD import AutoCatCore -enum QuickAction { - case none - case check - case checkNumber(String, VehicleEventDto?) - case addVoiceRecord - case openReport(String) -} - @main class AppDelegate: UIResponder, UIApplicationDelegate { - var quickAction: QuickAction = .none - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let config = Realm.Configuration( @@ -94,18 +84,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. - #if !targetEnvironment(macCatalyst) - - if let shortcutItem = options.shortcutItem { - if shortcutItem.type == "CheckNumberAction" { - self.quickAction = .check - } else if shortcutItem.type == "AddVoiceRecordAction" { - self.quickAction = .addVoiceRecord - } - } - - #endif - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } diff --git a/AutoCat/Controllers/RecordsController.swift b/AutoCat/Controllers/RecordsController.swift index d8e495d..4494532 100644 --- a/AutoCat/Controllers/RecordsController.swift +++ b/AutoCat/Controllers/RecordsController.swift @@ -38,26 +38,6 @@ class RecordsController: UIViewController, UITableViewDelegate { self.tableView.delegate = self } - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - self.handleQuickActions() - } - - func handleQuickActions() { - guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } - - switch ad.quickAction { - case .addVoiceRecord: - ad.quickAction = .none - if let addButton = self.navigationItem.rightBarButtonItem { - self.onAddVoiceRecord(addButton) - } - break - default: - break - } - } - func donateUserActivity() { let activityId = "pro.aliencat.autocat.addVoiceRecord" let activity = NSUserActivity(activityType: activityId) @@ -327,8 +307,7 @@ class RecordsController: UIViewController, UITableViewDelegate { } func check(number: String, event: VehicleEventDto?) { - guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } - ad.quickAction = .checkNumber(number, event) + // TODO: Implement checking number without quick action self.tabBarController?.selectedIndex = 0 } diff --git a/AutoCat/SceneDelegate.swift b/AutoCat/SceneDelegate.swift index a86c42b..8603345 100644 --- a/AutoCat/SceneDelegate.swift +++ b/AutoCat/SceneDelegate.swift @@ -14,14 +14,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } + + var number: String? if let activity = connectionOptions.userActivities.first { if let url = activity.webpageURL { if let param = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first, let token = param.value { if let jwt = JWT(string: token) { - ad.quickAction = .openReport(jwt.payload.plateNumber) + number = jwt.payload.plateNumber } } } @@ -29,7 +30,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { Task { try? await registerServices() - setupRootController(scene: scene) + setupRootController(scene: scene, openReport: number) } } @@ -61,7 +62,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { container.register(VehicleServiceProtocol.self, instance: vehicleService) } - func setupRootController(scene: UIScene) { + func setupRootController(scene: UIScene, openReport number: String?) { guard let windowScene = (scene as? UIWindowScene) else { return } @@ -75,6 +76,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { self.window?.rootViewController = storyboard.instantiateViewController(identifier: "AuthController") } else { self.window?.rootViewController = storyboard.instantiateViewController(identifier: "MainSplitController") + if let number { + Task { await openReport(with: number) } + } } #if targetEnvironment(macCatalyst)