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:
dankito 2020-07-31 00:27:09 +02:00
parent d653cd913b
commit 341b68fec1
1 changed files with 14 additions and 7 deletions

View File

@ -71,17 +71,24 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher {
}
func saveUrlToFile(url: String, file: URL) {
let response = UrlSessionWebClient().getData(url)
if let response = response {
do {
try UIImage(data: response)?.pngData()?.write(to: file)
} catch {
NSLog("Could not save url '\(url)' to file '\(file): \(error)")
if let remoteUrl = URL.encoded(url) {
if let fileData = try? Data(contentsOf: remoteUrl) {
do {
try UIImage(data: fileData)?.pngData()?.write(to: file)
} catch {
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() {
do {