From 6c6a7685b63205e3e97204a808ac4c0b274d121e Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 16 Dec 2023 16:52:50 +0000 Subject: [PATCH] update storage directory for PersistentStorage --- .../Amplitude/Storages/PersistentStorage.swift | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Sources/Amplitude/Storages/PersistentStorage.swift b/Sources/Amplitude/Storages/PersistentStorage.swift index e91aece0..e79c17df 100644 --- a/Sources/Amplitude/Storages/PersistentStorage.swift +++ b/Sources/Amplitude/Storages/PersistentStorage.swift @@ -239,21 +239,18 @@ extension PersistentStorage { } internal func getEventsStorageDirectory(createDirectory: Bool = true) -> URL { - // tvOS doesn't have access to document - // macOS /Documents dir might be synced with iCloud - #if os(tvOS) || os(macOS) - let searchPathDirectory = FileManager.SearchPathDirectory.cachesDirectory - #else - let searchPathDirectory = FileManager.SearchPathDirectory.documentDirectory - #endif - + let searchPathDirectory = FileManager.SearchPathDirectory.applicationSupportDirectory let urls = fileManager.urls(for: searchPathDirectory, in: .userDomainMask) let docUrl = urls[0] - let storageUrl = docUrl.appendingPathComponent("amplitude/\(eventsFileKey)/") + var storageUrl = docUrl.appendingPathComponent("amplitude/\(eventsFileKey)/") if createDirectory { // try to create it, will fail if already exists. // tvOS, watchOS regularly clear out data. - try? FileManager.default.createDirectory(at: storageUrl, withIntermediateDirectories: true, attributes: nil) + var values = URLResourceValues() + values.isExcludedFromBackup = true + try? FileManager.default.createDirectory( + at: storageUrl, withIntermediateDirectories: true, attributes: nil) + try? storageUrl.setResourceValues(values) } return storageUrl }