Browse Source

fix SAVE TO PHOTO GALLERY

marinofaggiana 4 năm trước cách đây
mục cha
commit
d7e2e7cc83
1 tập tin đã thay đổi với 33 bổ sung0 xóa
  1. 33 0
      iOSClient/Networking/NCNetworkingNotificationCenter.swift

+ 33 - 0
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -105,6 +105,32 @@ import Foundation
                         
                         NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
                         
+                    case selectorSaveAlbum:
+                        
+                        let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                        let status = PHPhotoLibrary.authorizationStatus()
+
+                        if metadata.typeFile == k_metadataTypeFile_image && status == PHAuthorizationStatus.authorized {
+                            
+                            if let image = UIImage.init(contentsOfFile: fileNamePath) {
+                                UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                            } else {
+                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            }
+                            
+                        } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
+                            
+                            if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
+                                UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                            } else {
+                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            }
+                            
+                        } else if status != PHAuthorizationStatus.authorized {
+                            
+                            NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                        }
+                       
                     default:
                         
                         break
@@ -188,6 +214,13 @@ import Foundation
         }
     }
     
+    @objc func SaveAlbum(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
+        
+        if error != nil {
+            NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+        }
+    }
+    
     //MARK: - Upload
 
     @objc func uploadedFile(_ notification: NSNotification) {