Эх сурвалжийг харах

coding

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 жил өмнө
parent
commit
93d8ba783d

+ 1 - 0
iOSClient/AppDelegate.swift

@@ -86,6 +86,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         CCUtility.createDirectoryStandard()
         CCUtility.emptyTemporaryDirectory()
+        NCUtility.shared.clearCacheDirectory("com.limit-point.LivePhoto")
 
         // Activated singleton
         _ = NCActionCenter.shared

+ 31 - 0
iOSClient/Extensions/UIImage+Extension.swift

@@ -232,4 +232,35 @@ extension UIImage {
         }
         return image
     }
+
+    var heic: Data? { heic() }
+    var cgImageOrientation: CGImagePropertyOrientation { .init(imageOrientation) }
+
+    func heic(compressionQuality: CGFloat = 1) -> Data? {
+        guard
+            let mutableData = CFDataCreateMutable(nil, 0),
+            let destination = CGImageDestinationCreateWithData(mutableData, "public.heic" as CFString, 1, nil),
+            let cgImage = cgImage
+        else { return nil }
+        CGImageDestinationAddImage(destination, cgImage, [kCGImageDestinationLossyCompressionQuality: compressionQuality, kCGImagePropertyOrientation: cgImageOrientation.rawValue] as CFDictionary)
+        guard CGImageDestinationFinalize(destination) else { return nil }
+        return mutableData as Data
+    }
+}
+
+extension CGImagePropertyOrientation {
+    init(_ uiOrientation: UIImage.Orientation) {
+        switch uiOrientation {
+        case .up: self = .up
+        case .upMirrored: self = .upMirrored
+        case .down: self = .down
+        case .downMirrored: self = .downMirrored
+        case .left: self = .left
+        case .leftMirrored: self = .leftMirrored
+        case .right: self = .right
+        case .rightMirrored: self = .rightMirrored
+        @unknown default:
+            fatalError()
+        }
+    }
 }

+ 3 - 4
iOSClient/Menu/NCOperationSaveLivePhoto.swift

@@ -1,5 +1,5 @@
 //
-//  NCooo.swift
+//  NCOperationSaveLivePhoto.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 19/10/23.
@@ -21,7 +21,6 @@
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 //
 
-
 import UIKit
 import Queuer
 import JGProgressHUD
@@ -97,8 +96,8 @@ class NCOperationSaveLivePhoto: ConcurrentOperation {
         NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
             self.hud.progress = Float(progress)
         }, completion: { _, resources in
-            if resources != nil {
-                NCLivePhoto.saveToLibrary(resources!) { result in
+            if let resources {
+                NCLivePhoto.saveToLibrary(resources) { result in
                     DispatchQueue.main.async {
                         if !result {
                             self.hud.indicatorView = JGProgressHUDErrorIndicatorView()

+ 21 - 0
iOSClient/Utility/NCUtility.swift

@@ -841,4 +841,25 @@ class NCUtility: NSObject {
 
         return (usedmegabytes, totalmegabytes)
     }
+
+    /* "com.limit-point.LivePhoto" */
+    func clearCacheDirectory(_ directory: String) {
+        if let cacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first {
+            let fullDirectory = cacheURL.appendingPathComponent(directory, isDirectory: true)
+            let fileManager = FileManager.default
+            do {
+                // Get the directory contents urls (including subfolders urls)
+                let directoryContents = try FileManager.default.contentsOfDirectory( at: cacheURL, includingPropertiesForKeys: nil, options: [])
+                for file in directoryContents {
+                    do {
+                        try fileManager.removeItem(at: file)
+                    } catch let error as NSError {
+                        debugPrint("Ooops! Something went wrong: \(error)")
+                    }
+                }
+            } catch let error as NSError {
+                print(error.localizedDescription)
+            }
+        }
+    }
 }