From b1a9eb60c19d2d665a871bb286b7ab113501fdee Mon Sep 17 00:00:00 2001 From: Gianni Carlo Date: Fri, 26 Apr 2024 11:36:09 -0500 Subject: [PATCH 1/2] Add missing privacy info for file timestamp --- BookPlayer/PrivacyInfo.xcprivacy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BookPlayer/PrivacyInfo.xcprivacy b/BookPlayer/PrivacyInfo.xcprivacy index 4088038e..a5dff940 100644 --- a/BookPlayer/PrivacyInfo.xcprivacy +++ b/BookPlayer/PrivacyInfo.xcprivacy @@ -4,6 +4,14 @@ NSPrivacyAccessedAPITypes + + NSPrivacyAccessedAPITypeReasons + + 3B52.1 + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPIType NSPrivacyAccessedAPICategoryDiskSpace From 2db4aa83e13d70146e1bf29d126df33aaec17c96 Mon Sep 17 00:00:00 2001 From: Gianni Carlo Date: Fri, 26 Apr 2024 12:02:09 -0500 Subject: [PATCH 2/2] Move tmp files to Documents folder --- .../Coordinators/LibraryListCoordinator.swift | 11 ++++++++++- .../ItemList Screen/ItemListViewModel.swift | 14 +++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/BookPlayer/Coordinators/LibraryListCoordinator.swift b/BookPlayer/Coordinators/LibraryListCoordinator.swift index b90ac7cf..6019d822 100644 --- a/BookPlayer/Coordinators/LibraryListCoordinator.swift +++ b/BookPlayer/Coordinators/LibraryListCoordinator.swift @@ -203,8 +203,17 @@ class LibraryListCoordinator: ItemListCoordinator, UINavigationControllerDelegat } func processFiles(urls: [URL]) { + let temporaryDirectoryPath = FileManager.default.temporaryDirectory.absoluteString + let documentsFolder = DataManager.getDocumentsFolderURL() + for url in urls { - self.importManager.process(url) + /// At some point (iOS 17?), the OS stopped sending the picked files to the Documents/Inbox folder, instead + /// it's now sent to a temp folder that can't be relied on to keep the file existing until the import is finished + if url.absoluteString.contains(temporaryDirectoryPath) { + try! FileManager.default.moveItem(at: url, to: documentsFolder) + } else { + importManager.process(url) + } } } diff --git a/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift b/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift index f79dc2fe..74432ee5 100644 --- a/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift +++ b/BookPlayer/Library/ItemList Screen/ItemListViewModel.swift @@ -992,8 +992,20 @@ class ItemListViewModel: ViewModelProtocol { // MARK: - Import related functions extension ItemListViewModel { func handleNewFiles(_ urls: [URL]) { + let temporaryDirectoryPath = FileManager.default.temporaryDirectory.absoluteString + let documentsFolder = DataManager.getDocumentsFolderURL() + for url in urls { - importManager.process(url) + /// At some point (iOS 17?), the OS stopped sending the picked files to the Documents/Inbox folder, instead + /// it's now sent to a temp folder that can't be relied on to keep the file existing until the import is finished + if url.absoluteString.contains(temporaryDirectoryPath) { + let destinationURL = documentsFolder.appendingPathComponent(url.lastPathComponent) + if !FileManager.default.fileExists(atPath: destinationURL.path) { + try! FileManager.default.copyItem(at: url, to: destinationURL) + } + } else { + importManager.process(url) + } } }