Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Application Support Directory for Persistent Storage #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions Sources/Amplitude/Storages/PersistentStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,18 @@ extension PersistentStorage {
}

internal func getEventsStorageDirectory(createDirectory: Bool = true) -> URL {
// TODO: Update to use applicationSupportDirectory for all platforms (this will require a migration)
// let searchPathDirectory = FileManager.SearchPathDirectory.applicationSupportDirectory
// 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/\(appPath ?? "")\(eventsFileKey)/")
var storageUrl = docUrl.appendingPathComponent("amplitude/\(appPath ?? "")\(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
}
Expand Down