Harden watch sync and App Group storage
This commit is contained in:
@@ -157,6 +157,7 @@ private enum WatchFuelCache {
|
||||
static let appGroupSuite = "group.com.apt.fuelboard"
|
||||
static let favouritesKey = "fuelboard.favourites"
|
||||
static let stationsKey = "fuelboard.stations"
|
||||
static let stationsFileName = "fuelboard.stations.json"
|
||||
static let fuelKey = "fuelboard.selectedFuel"
|
||||
static let distanceUnitKey = "fuelboard.distanceUnit"
|
||||
static let priceStyleKey = "fuelboard.priceDisplayStyle"
|
||||
@@ -228,7 +229,17 @@ private enum WatchFuelCache {
|
||||
}
|
||||
|
||||
static func loadStations() -> [WatchStation] {
|
||||
guard let data = defaults()?.data(forKey: stationsKey),
|
||||
let fileData: Data?
|
||||
if let container = FileManager.default.containerURL(
|
||||
forSecurityApplicationGroupIdentifier: appGroupSuite
|
||||
) {
|
||||
let url = container.appendingPathComponent(stationsFileName)
|
||||
fileData = try? Data(contentsOf: url)
|
||||
} else {
|
||||
fileData = nil
|
||||
}
|
||||
let data = fileData ?? defaults()?.data(forKey: stationsKey)
|
||||
guard let data,
|
||||
let stations = try? JSONDecoder().decode([WatchStation].self, from: data) else {
|
||||
return []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user