From 168aed2b6208986e568084917ef8c5fbba129624 Mon Sep 17 00:00:00 2001 From: Lisheng Guan Date: Mon, 16 Dec 2024 14:21:32 +0800 Subject: [PATCH] Associate mmb file with MMEX app via onOpenURL --- MMEX.xcodeproj/project.pbxproj | 6 ++--- MMEX/App/AppDelegate.swift | 42 ---------------------------------- MMEX/App/MMEXApp.swift | 9 ++------ MMEX/Info.plist | 7 ------ 4 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 MMEX/App/AppDelegate.swift diff --git a/MMEX.xcodeproj/project.pbxproj b/MMEX.xcodeproj/project.pbxproj index 507ddab..8f02444 100644 --- a/MMEX.xcodeproj/project.pbxproj +++ b/MMEX.xcodeproj/project.pbxproj @@ -182,7 +182,6 @@ A3462F662C94854800F79145 /* ExportableEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3462F652C94854800F79145 /* ExportableEntity.swift */; }; A3462F6A2C948CDB00F79145 /* ExportableEntityDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3462F692C948CDB00F79145 /* ExportableEntityDocument.swift */; }; A350BDC12CA26415006669D5 /* TransactionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A350BDC02CA26415006669D5 /* TransactionViewModel.swift */; }; - A36599042D0FCB0500F506B6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36599032D0FCB0500F506B6 /* AppDelegate.swift */; }; A379C1A92CA3B9EB00CC8E2C /* AssetListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A379C1A82CA3B9EB00CC8E2C /* AssetListView.swift */; }; A37E7D842C9AC14800B4ECFC /* ManageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37E7D832C9AC14800B4ECFC /* ManageView.swift */; }; A37E7D862C9AC2D000B4ECFC /* InfoAboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A37E7D852C9AC2D000B4ECFC /* InfoAboutView.swift */; }; @@ -408,7 +407,6 @@ A3462F652C94854800F79145 /* ExportableEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportableEntity.swift; sourceTree = ""; }; A3462F692C948CDB00F79145 /* ExportableEntityDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExportableEntityDocument.swift; sourceTree = ""; }; A350BDC02CA26415006669D5 /* TransactionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionViewModel.swift; sourceTree = ""; }; - A36599032D0FCB0500F506B6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A379C1A82CA3B9EB00CC8E2C /* AssetListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListView.swift; sourceTree = ""; }; A37E7D832C9AC14800B4ECFC /* ManageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManageView.swift; sourceTree = ""; }; A37E7D852C9AC2D000B4ECFC /* InfoAboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoAboutView.swift; sourceTree = ""; }; @@ -496,7 +494,6 @@ 929EF6702CA3676B0051A3E6 /* MMEXDocument.swift */, A3C1425E2C8DE70300D3CEC0 /* MMEXDatabase.swift */, A3C1422C2C89751500D3CEC0 /* ContentView.swift */, - A36599032D0FCB0500F506B6 /* AppDelegate.swift */, ); path = App; sourceTree = ""; @@ -1155,7 +1152,6 @@ 925EABB22CCFFC2E003CEAB3 /* Reload.swift in Sources */, A337428A2CA8E72C00698466 /* InsightsSummary.swift in Sources */, A3C142672C8F2AF500D3CEC0 /* TransactionData.swift in Sources */, - A36599042D0FCB0500F506B6 /* AppDelegate.swift in Sources */, 925EAC0F2CDA8B1A003CEAB3 /* TagSearch.swift in Sources */, 92F686032CF0EE7700171A6A /* BudgetSearch.swift in Sources */, 925EAC202CDAADFB003CEAB3 /* AttachmentValidation.swift in Sources */, @@ -1460,6 +1456,7 @@ INFOPLIST_KEY_CFBundleDisplayName = MMEX; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance"; INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; @@ -1495,6 +1492,7 @@ INFOPLIST_KEY_CFBundleDisplayName = MMEX; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance"; INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; diff --git a/MMEX/App/AppDelegate.swift b/MMEX/App/AppDelegate.swift deleted file mode 100644 index 22a15d4..0000000 --- a/MMEX/App/AppDelegate.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// AppDelegate.swift -// MMEX -// -// Created by Lisheng Guan on 2024/12/16. -// - -import UIKit -import OSLog -import MobileCoreServices - - -class AppDelegate: NSObject, UIApplicationDelegate { - func application( - _ application: UIApplication, - open url: URL, - options: [UIApplication.OpenURLOptionsKey : Any] = [:] - ) -> Bool { - log.debug("File opened with URL: \(url)") - - // Ensure it's an .mmb file - guard url.pathExtension == "mmb" else { - log.error("Unsupported file type: \(url.pathExtension)") - return false - } - - // Handle the .mmb file (pass it to your ViewModel or other logic) - handleMMBFile(url) - - return true - } - - private func handleMMBFile(_ url: URL) { - log.debug("Processing .mmb file at: \(url.path)") - - // Example: pass the URL to your ViewModel - NotificationCenter.default.post( - name: Notification.Name("MMEXOpenFile"), - object: url - ) - } -} diff --git a/MMEX/App/MMEXApp.swift b/MMEX/App/MMEXApp.swift index 90e56cc..bbd7227 100644 --- a/MMEX/App/MMEXApp.swift +++ b/MMEX/App/MMEXApp.swift @@ -16,7 +16,6 @@ let log = Logger( @main struct MMEXApp: App { - @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate @StateObject private var pref = Preference() @StateObject private var vm = ViewModel(withStoredDatabase: ()) @@ -43,12 +42,8 @@ struct MMEXApp: App { track(pref: pref) } .handlesExternalEvents(preferring: Set(["mmb"]), allowing: Set(["*"])) - .onReceive(NotificationCenter.default.publisher(for: Notification.Name("MMEXOpenFile"))) { notification in - log.debug("DEBUG: onReceive") - if let url = notification.object as? URL { - log.debug("File URL received in SwiftUI: \(url.path)") - // vm.openDatabase(at: url) // Example: Replace with your actual ViewModel logic - } + .onOpenURL { url in + vm.openDatabase(at: url) } .environmentObject(pref) .environmentObject(vm) diff --git a/MMEX/Info.plist b/MMEX/Info.plist index 978a3dc..8c9e8c8 100644 --- a/MMEX/Info.plist +++ b/MMEX/Info.plist @@ -17,13 +17,6 @@ - UIApplicationSceneManifest - - UIApplicationSupportsMultipleScenes - - UISceneConfigurations - - UTExportedTypeDeclarations