Browse Source

new Auto Upload

marinofaggiana 4 years ago
parent
commit
d6f4d4d9d3

+ 14 - 0
iOSClient/AutoUpload/NCAutoUpload.swift

@@ -31,6 +31,20 @@ class NCAutoUpload: NSObject {
         return instance
     }()
     
+    func initStateAutoUpload() {
+        
+        if let account = NCManageDatabase.shared.getAccountActive() {
+            if account.autoUpload {
+                // [self setupAutoUpload];
+                
+                if account.autoUploadBackground {
+                    // [self checkIfLocationIsEnabled];
+                }
+            }
+        } else {
+            NCManageLocation.shared.stopSignificantChangeUpdates()
+        }
+    }
 }
 
 //MARK: -

+ 2 - 1
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -841,7 +841,8 @@
 "_err_asset_not_found_locally_"         = "Error: Photo/video not found locally, removed from upload";
 "_err_asset_not_found_"                 = "Error: Photo/video not found, removed from upload";
 "_err_e2ee_app_version_"                = "Error: The version of app End-to-End encryption is not compatible, please update your server";
-"_err_permission_microphone_"           = "Please allow microphone usage from Settings";
+"_err_permission_microphone_"           = "Please allow Microphone usage from Settings";
+"_err_permission_photolibrary_"         = "Please allow Photos - All Photos from Settings";
 
 // QRCode
 

+ 37 - 0
iOSClient/Utility/NCUtility.swift

@@ -481,5 +481,42 @@ class NCUtility: NSObject {
             break
         }
     }
+    
+    func askPhotoLibraryPermission(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+     
+        switch PHPhotoLibrary.authorizationStatus() {
+        case PHAuthorizationStatus.authorized:
+            completion(true)
+            break
+        case PHAuthorizationStatus.denied, PHAuthorizationStatus.limited, PHAuthorizationStatus.restricted:
+            let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_photolibrary_", comment: ""), preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { action in
+                UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
+                completion(false)
+            }))
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
+                completion(false)
+            }))
+            viewController.present(alert, animated: true, completion: nil)
+            break
+        case PHAuthorizationStatus.notDetermined:
+            PHPhotoLibrary.requestAuthorization { (allowed) in
+                DispatchQueue.main.async {
+                    if allowed == PHAuthorizationStatus.authorized {
+                        completion(true)
+                    } else {
+                        completion(false)
+                    }
+                }
+            }
+            break
+        default:
+            break
+        }
+    }
+    
+    func askLocationManagerPermission(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+        
+    }
 }