From 62f5a13fd618c5b60b030ccce8e4897767adff30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sun, 17 Aug 2025 12:03:41 +0200 Subject: [PATCH] Fix receiving files on iOS --- NearbyShare/Util/SaveFilesManager.swift | 16 ++++++++++++---- QuickDrop.xcodeproj/project.pbxproj | 6 ++++++ QuickDropiOS/Info.plist | 8 ++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 QuickDropiOS/Info.plist diff --git a/NearbyShare/Util/SaveFilesManager.swift b/NearbyShare/Util/SaveFilesManager.swift index f6239b3..1bd8dee 100644 --- a/NearbyShare/Util/SaveFilesManager.swift +++ b/NearbyShare/Util/SaveFilesManager.swift @@ -143,6 +143,9 @@ public class SaveFilesManager { public func getSaveDirectory() -> URL { + + // Not supported on iOS + #if os(macOS) if let securityScopeUrl = securityScopeUrl { log("Using existing security scope URL: \(securityScopeUrl)") return securityScopeUrl @@ -150,9 +153,7 @@ public class SaveFilesManager { if let bookmarkData = UserDefaults.standard.data(forKey: UserDefaultsKeys.saveFolderBookmark.rawValue) { var isStale = false - - // Not supported on iOS - #if os(macOS) + do { let url = try URL(resolvingBookmarkData: bookmarkData, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale) @@ -170,7 +171,6 @@ public class SaveFilesManager { } catch { log("Failed to resolve bookmark: \(error), using default downloads folder.") } - #endif } do { @@ -178,6 +178,14 @@ public class SaveFilesManager { } catch { fatalError("Failed to get downloads directory: \(error)") } + #else + // Return the documents directory for iOS + do { + return try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true).resolvingSymlinksInPath() + } catch { + fatalError("Failed to get documents directory: \(error)") + } + #endif } diff --git a/QuickDrop.xcodeproj/project.pbxproj b/QuickDrop.xcodeproj/project.pbxproj index df6a290..3937006 100644 --- a/QuickDrop.xcodeproj/project.pbxproj +++ b/QuickDrop.xcodeproj/project.pbxproj @@ -248,6 +248,7 @@ EB979F922E50CA23008B8C5C /* QuickDropiOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickDropiOSApp.swift; sourceTree = ""; }; EB979F992E50CAA6008B8C5C /* PieProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PieProgressView.swift; sourceTree = ""; }; EB97A00E2E511120008B8C5C /* ReceiveModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiveModel.swift; sourceTree = ""; }; + EB97A0162E51DF4F008B8C5C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; EB99257F2E45D53E00357055 /* sharing_enums.pb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = sharing_enums.pb.swift; sourceTree = ""; }; EBC05C5A2E33936C00EECC18 /* ErrorAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorAlertHandler.swift; sourceTree = ""; }; EBC05C6D2E33B57D00EECC18 /* Converter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Converter.swift; sourceTree = ""; }; @@ -440,6 +441,7 @@ EB979F932E50CA23008B8C5C /* QuickDropiOS */ = { isa = PBXGroup; children = ( + EB97A0162E51DF4F008B8C5C /* Info.plist */, EB979F8D2E50CA23008B8C5C /* Configuration.swift */, EB979F8E2E50CA23008B8C5C /* ContentView.swift */, EB979F8F2E50CA23008B8C5C /* FilePicker.swift */, @@ -1131,8 +1133,10 @@ ENABLE_PREVIEWS = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = QuickDropiOS/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = QuickDrop; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Local network access is required to scan and connect to devices."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; @@ -1171,8 +1175,10 @@ ENABLE_PREVIEWS = YES; GCC_C_LANGUAGE_STANDARD = gnu17; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = QuickDropiOS/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = QuickDrop; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES; INFOPLIST_KEY_NSLocalNetworkUsageDescription = "Local network access is required to scan and connect to devices."; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; diff --git a/QuickDropiOS/Info.plist b/QuickDropiOS/Info.plist new file mode 100644 index 0000000..ff579a6 --- /dev/null +++ b/QuickDropiOS/Info.plist @@ -0,0 +1,8 @@ + + + + + UIFileSharingEnabled + + +