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,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 {
|
||||
|
|
Loading…
Reference in New Issue