浏览代码

new auto upload

marinofaggiana 4 年之前
父节点
当前提交
3caef78b94
共有 2 个文件被更改,包括 16 次插入4 次删除
  1. 14 2
      iOSClient/AutoUpload/NCAutoUpload.swift
  2. 2 2
      iOSClient/Utility/NCAskAuthorization.swift

+ 14 - 2
iOSClient/AutoUpload/NCAutoUpload.swift

@@ -31,20 +31,32 @@ class NCAutoUpload: NSObject {
         return instance
     }()
     
-    func initStateAutoUpload() {
+    func initStateAutoUpload(viewController: UIViewController?) {
         
         if let account = NCManageDatabase.shared.getAccountActive() {
             if account.autoUpload {
                 // [self setupAutoUpload];
                 
                 if account.autoUploadBackground {
-                    // [self checkIfLocationIsEnabled];
+                    NCAskAuthorization.shared.askAuthorizationLocationManager(viewController: viewController) { (hasPermissions) in
+                        if hasPermissions {
+                            NCManageLocation.shared.startSignificantChangeUpdates()
+                        }
+                    }
                 }
             }
         } else {
             NCManageLocation.shared.stopSignificantChangeUpdates()
         }
     }
+    
+    @objc func changeLocation() {
+        
+        if let account = NCManageDatabase.shared.getAccountActive() {
+            if account.autoUpload && account.autoUploadBackground && UIApplication.shared.applicationState == UIApplication.State.background {
+            }
+        }
+    }
 }
 
 //MARK: -

+ 2 - 2
iOSClient/Utility/NCAskAuthorization.swift

@@ -97,7 +97,7 @@ class NCAskAuthorization: NSObject {
         }
     }
     
-    func askAuthorizationLocationManager(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+    func askAuthorizationLocationManager(viewController: UIViewController?, completion: @escaping (_ hasPermissions: Bool)->()) {
         
         switch CLLocationManager.authorizationStatus() {
         case CLAuthorizationStatus.authorizedAlways:
@@ -112,7 +112,7 @@ class NCAskAuthorization: NSObject {
             alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
                 completion(false)
             }))
-            viewController.present(alert, animated: true, completion: nil)
+            viewController?.present(alert, animated: true, completion: nil)
             break
         case CLAuthorizationStatus.notDetermined:
             NCManageLocation.shared.startSignificantChangeUpdates()