As documents folder path points after each restart to a different folder, saving absolute paths obviously doesn't work. Using now (temporarily) UserDefaults to save bank icons. To encapsulate this added method readContentOfFile().
This commit is contained in:
parent
d653cd913b
commit
341b68fec1
|
@ -71,16 +71,23 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveUrlToFile(url: String, file: URL) {
|
func saveUrlToFile(url: String, file: URL) {
|
||||||
let response = UrlSessionWebClient().getData(url)
|
if let remoteUrl = URL.encoded(url) {
|
||||||
|
if let fileData = try? Data(contentsOf: remoteUrl) {
|
||||||
if let response = response {
|
|
||||||
do {
|
do {
|
||||||
try UIImage(data: response)?.pngData()?.write(to: file)
|
try UIImage(data: fileData)?.pngData()?.write(to: file)
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("Could not save url '\(url)' to file '\(file): \(error)")
|
NSLog("Could not save url '\(url)' to file '\(file): \(error)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not indented for this kind of data but at least it works
|
||||||
|
UserDefaults.standard.set(fileData, forKey: file.absoluteString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readContentOfFile(_ filePath: String) -> Data? {
|
||||||
|
return UserDefaults.standard.data(forKey: filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func deleteAll() {
|
func deleteAll() {
|
||||||
|
|
Loading…
Reference in New Issue