Răsfoiți Sursa

new auto upload

marinofaggiana 4 ani în urmă
părinte
comite
6f1e586396

+ 3 - 3
iOSClient/AppDelegate.m

@@ -194,7 +194,7 @@
     [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
     
     // Initialize Auto upload
-    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
+    [[NCAutoUpload shared] initAutoUploadWithViewController:nil];
     
     // Read active directory
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCBrandGlobal.shared.notificationCenterReloadDataSourceNetworkForced object:nil];
@@ -272,7 +272,7 @@
     }
     
     // Start Auto Upload
-    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
+    [[NCAutoUpload shared] initAutoUploadWithViewController:nil];
     
     // Start services
     [[NCService shared] startRequestServicesServer];
@@ -520,7 +520,7 @@
     [[NCCommunicationCommon shared] writeLog:@"Start perform Fetch With Completion Handler"];
     
     // Verify new photo
-    [[NCAutoUpload shared] initStateAutoUploadWithViewController:nil];
+    [[NCAutoUpload shared] initAutoUploadWithViewController:nil];
     
     // after 20 sec
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

+ 26 - 33
iOSClient/Networking/NCAutoUpload.swift

@@ -69,33 +69,37 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
     }
     
     func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
-        statusAuthorizationLocationChanged()
+        NCManageDatabase.shared.setAccountAutoUploadProperty("autoUploadBackground", state: false)
+        self.stopSignificantChangeUpdates()
     }
     
     func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
-        statusAuthorizationLocationChanged()
-    }
-    
-    func statusAuthorizationLocationChanged() {
         NCManageDatabase.shared.setAccountAutoUploadProperty("autoUploadBackground", state: false)
         self.stopSignificantChangeUpdates()
     }
     
     // MARK: -
     
-    @objc func initStateAutoUpload(viewController: UIViewController?) {
+    @objc func initAutoUpload(viewController: UIViewController?) {
         
         if let account = NCManageDatabase.shared.getAccountActive() {
             if account.autoUpload {
-                setupAutoUpload()
-                if account.autoUploadBackground {
-                    NCAskAuthorization.shared.askAuthorizationLocationManager(viewController: appDelegate.window.rootViewController) { (hasPermissions) in
-                        if hasPermissions {
-                            self.startSignificantChangeUpdates()
-                        } else {
-                            NCManageDatabase.shared.setAccountAutoUploadProperty("autoUploadBackground", state: false)
-                            self.stopSignificantChangeUpdates()
+                NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: viewController) { (hasPermission) in
+                    if hasPermission {
+                        self.uploadNewAssets()
+                        if account.autoUploadBackground {
+                            NCAskAuthorization.shared.askAuthorizationLocationManager(viewController: viewController) { (hasPermissions) in
+                                if hasPermissions {
+                                    self.startSignificantChangeUpdates()
+                                } else {
+                                    NCManageDatabase.shared.setAccountAutoUploadProperty("autoUploadBackground", state: false)
+                                    self.stopSignificantChangeUpdates()
+                                }
+                            }
                         }
+                    } else {
+                        NCManageDatabase.shared.setAccountAutoUploadProperty("autoUpload", state: false)
+                        self.stopSignificantChangeUpdates()
                     }
                 }
             }
@@ -104,20 +108,7 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
         }
     }
     
-    @objc func setupAutoUpload() {
-        
-        NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window.rootViewController) { (hasPermission) in
-            if hasPermission {
-                self.uploadNewAssets()
-            } else {
-                NCManageDatabase.shared.setAccountAutoUploadProperty("autoUpload", state: false)
-                self.stopSignificantChangeUpdates()
-            }
-        }
-        
-    }
-    
-    @objc func setupAutoUploadFull() {
+    @objc func autoUploadFullPhotos() {
         NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window.rootViewController) { (hasPermission) in
             if hasPermission {
                 self.uploadAssetsNewAndFull(selector: NCBrandGlobal.shared.selectorUploadAutoUploadAll)
@@ -125,7 +116,7 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
         }
     }
     
-    @objc func uploadNewAssets() {
+    func uploadNewAssets() {
         NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window.rootViewController) { (hasPermission) in
             if hasPermission {
                 self.uploadAssetsNewAndFull(selector: NCBrandGlobal.shared.selectorUploadAutoUpload)
@@ -133,6 +124,12 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
         }
     }
     
+    private func uploadAssetsNewAndFull(selector: String) {
+        
+    }
+    
+    // MARK: -
+
     @objc func alignPhotoLibrary() {
         if let account = NCManageDatabase.shared.getAccountActive() {
             getCameraRollAssets(account: account, selector: NCBrandGlobal.shared.selectorUploadAutoUploadAll, alignPhotoLibrary: true) { (assets) in
@@ -145,10 +142,6 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
         }
     }
     
-    private func uploadAssetsNewAndFull(selector: String) {
-        
-    }
-    
     private func getCameraRollAssets(account: tableAccount, selector: String, alignPhotoLibrary: Bool, completion: @escaping (_ assets: [PHAsset]?)->()) {
                 
         NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window.rootViewController) { (hasPermission) in

+ 1 - 1
iOSClient/Settings/CCManageAutoUpload.m

@@ -311,7 +311,7 @@
         
         if ([[rowDescriptor.value valueData] boolValue] == YES) {
             
-            [[NCAutoUpload shared] setupAutoUploadFull];
+            [[NCAutoUpload shared] autoUploadFullPhotos];
             [[NCManageDatabase shared] setAccountAutoUploadProperty:@"autoUploadFull" state:YES];
             
         } else {