marinofaggiana 4 роки тому
батько
коміт
ae4b5f12cf
1 змінених файлів з 31 додано та 0 видалено
  1. 31 0
      iOSClient/AppDelegate.swift

+ 31 - 0
iOSClient/AppDelegate.swift

@@ -370,6 +370,37 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     
     @objc func deleteAccount(_ account: String, wipe: Bool) {
         
+        // Push Notification
+        if let account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) {
+            NCPushNotification.shared().unsubscribingNextcloudServerPushNotification(account.account, urlBase: account.urlBase, user: account.user, withSubscribing: false)
+        }
+        
+        settingAccount("", urlBase: "", user: "", userID: "", password: "")
+        
+        let results = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@", account), sorted: "ocId", ascending: false)
+        for result in results {
+            CCUtility.removeFile(atPath: CCUtility.getDirectoryProviderStorageOcId(result.ocId))
+        }
+        NCManageDatabase.shared.clearDatabase(account: account, removeAccount: true)
+        
+        CCUtility.clearAllKeysEnd(toEnd: account)
+        CCUtility.clearAllKeysPushNotification(account)
+        CCUtility.setCertificateError(account, error: false)
+        CCUtility.setPassword(account, password: nil)
+        
+        if wipe {
+            let accounts = NCManageDatabase.shared.getAccounts()
+            if accounts?.count ?? 0 > 0 {
+                if let newAccount = accounts?.first {
+                    if let account = NCManageDatabase.shared.setAccountActive(newAccount) {
+                        settingAccount(account.account, urlBase: account.urlBase, user: account.user, userID: account.userID, password: CCUtility.getPassword(account.account))
+                        NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterInitializeMain)
+                    }
+                }
+            } else {
+                openLogin(viewController: window?.rootViewController, selector: NCBrandGlobal.shared.introLogin, openLoginWeb: false)
+            }
+        }
     }
     
     // MARK: - TOPasscodeViewController