Browse Source

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
52a0192d97
1 changed files with 15 additions and 13 deletions
  1. 15 13
      iOSClient/Utility/NCUtility.swift

+ 15 - 13
iOSClient/Utility/NCUtility.swift

@@ -1031,20 +1031,22 @@ class NCUtility: NSObject {
         
         if !FileManager().fileExists(atPath: fileNamePath) {
             NextcloudKit.shared.getPreview(url: url, options: options) { account, data, error in
-                guard let data = data else { return completition(nil) }
                 var image: UIImage?
-                if let uiImage = UIImage(data: data) {
-                    image = uiImage.resizeImage(size: size)
-                } else if let svgImage = SVGKImage(data: data) {
-                    svgImage.size = size
-                    image = svgImage.uiImage
-                } else {
-                    print("error")
-                }
-                if let image = image {
-                    do {
-                        try image.pngData()?.write(to: URL(fileURLWithPath: fileNamePath), options: .atomic)
-                    } catch { }
+                if error == .success {
+                    guard let data = data else { return completition(nil) }
+                    if let uiImage = UIImage(data: data) {
+                        image = uiImage.resizeImage(size: size)
+                    } else if let svgImage = SVGKImage(data: data) {
+                        svgImage.size = size
+                        image = svgImage.uiImage
+                    } else {
+                        print("error")
+                    }
+                    if let image = image {
+                        do {
+                            try image.pngData()?.write(to: URL(fileURLWithPath: fileNamePath), options: .atomic)
+                        } catch { }
+                    }
                 }
                 completition(image)
             }