Browse Source

convertSVGtoPNGWriteToUserData

marinofaggiana 6 years ago
parent
commit
75f1c594e0
2 changed files with 3 additions and 77 deletions
  1. 3 2
      iOSClient/Networking/NCService.swift
  2. 0 75
      iOSClient/Utility/NCUtility.swift

+ 3 - 2
iOSClient/Networking/NCService.swift

@@ -69,7 +69,7 @@ class NCService: NSObject {
                     
                     // Download Logo
                     let fileNameThemingLogo = CCUtility.getStringUser(self.appDelegate.activeUser, activeUrl: self.appDelegate.activeUrl) + "-themingLogo.png"
-                    _ = NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true)
+                    NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: capabilities!.themingLogo, fileName: fileNameThemingLogo, width: 40, rewrite: true, closure: { (imageNamePath) in })
                     
                     // Download Theming Background
                     DispatchQueue.global().async {
@@ -132,7 +132,8 @@ class NCService: NSObject {
                                 for notification in listOfNotifications! {
                                     let id = (notification as! OCNotifications).idNotification
                                     if let icon = (notification as! OCNotifications).icon {
-                                        _ = NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false)
+                                        
+                                        NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, closure: { (imageNamePath) in })                                        
                                     }
                                     new = new + String(describing: id)
                                 }

+ 0 - 75
iOSClient/Utility/NCUtility.swift

@@ -254,81 +254,6 @@ class NCUtility: NSObject {
         return closure(imageNamePath)
     }
     
-    func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool) -> String? {
-        
-        var fileNamePNG = ""
-        
-        guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
-            return nil
-        }
-        guard let iconURL = URL(string: svgUrlString) else {
-            return nil
-        }
-        
-        if fileName == nil {
-            fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
-        } else {
-            fileNamePNG = fileName!
-        }
-        
-        let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG
-        
-        if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
-            
-            guard let imageData = try? Data(contentsOf:iconURL) else {
-                return nil
-            }
-            
-            if let image = UIImage.init(data: imageData) {
-                
-                var newImage: UIImage = image
-                
-                if width != nil {
-                    
-                    let ratio = image.size.height / image.size.width
-                    let newSize = CGSize(width: width!, height: width! * ratio)
-                    
-                    let renderFormat = UIGraphicsImageRendererFormat.default()
-                    renderFormat.opaque = false
-                    let renderer = UIGraphicsImageRenderer(size: CGSize(width: newSize.width, height: newSize.height), format: renderFormat)
-                    newImage = renderer.image {
-                        (context) in
-                        image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
-                    }
-                }
-                
-                guard let pngImageData = newImage.pngData() else {
-                    return nil
-                }
-                CCUtility.write(pngImageData, fileNamePath: imageNamePath)
-                
-            } else {
-                
-                guard let svgImage: SVGKImage = SVGKImage(contentsOf: iconURL) else {
-                    return nil
-                }
-                
-                if width != nil {
-                    let scale = svgImage.size.height / svgImage.size.width
-                    svgImage.size = CGSize(width: width!, height: width! * scale)
-                }
-                
-                guard let image: UIImage = svgImage.uiImage else {
-                    return nil
-                }
-                guard let pngImageData = image.pngData() else {
-                    return nil
-                }
-                
-                CCUtility.write(pngImageData, fileNamePath: imageNamePath)
-                
-                return imageNamePath
-            }
-        }
-        
-        return imageNamePath
-    }
-    
     @objc func startActivityIndicator(view: UIView, bottom: CGFloat) {
     
         activityIndicator.color = NCBrandColor.sharedInstance.brand