浏览代码

revert opening accounts in different lifecycle methods, due to keychain access protection. The adapted access policy should do the trick

cyberta 3 年之前
父节点
当前提交
f037819b21
共有 1 个文件被更改,包括 16 次插入22 次删除
  1. 16 22
      deltachat-ios/AppDelegate.swift

+ 16 - 22
deltachat-ios/AppDelegate.swift

@@ -72,7 +72,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             }
         }
 
-        openAccounts(dcAccounts)
+        let accountIds = dcAccounts.getAll()
+        for accountId in accountIds {
+            let dcContext = dcAccounts.get(id: accountId)
+            if !dcContext.isOpen() {
+                do {
+                    let secret = try KeychainManager.getAccountSecret(accountID: accountId)
+                    if !dcContext.open(passphrase: secret) {
+                        logger.error("Failed to open database for account \(accountId)")
+                    }
+                } catch KeychainError.unhandledError(let message, let status) {
+                    logger.error("Keychain error. \(message). Error status: \(status)")
+                } catch {
+                    logger.error("\(error)")
+                }
+            }
+        }
 
         if dcAccounts.getAll().isEmpty, dcAccounts.add() == 0 {
            fatalError("Could not initialize a new account.")
@@ -200,25 +215,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         logger.info("➡️ applicationProtectedDataWillBecomeUnavailable")
     }
 
-    func openAccounts(_ dcAccounts: DcAccounts) {
-        let accountIds = dcAccounts.getAll()
-        for accountId in accountIds {
-            let dcContext = dcAccounts.get(id: accountId)
-            if !dcContext.isOpen() {
-                do {
-                    let secret = try KeychainManager.getAccountSecret(accountID: accountId)
-                    if !dcContext.open(passphrase: secret) {
-                        logger.error("Failed to open database for account \(accountId)")
-                    }
-                } catch KeychainError.unhandledError(let message, let status) {
-                    logger.error("Keychain error. \(message). Error status: \(status)")
-                } catch {
-                    logger.error("\(error)")
-                }
-            }
-        }
-    }
-
     static func emitMsgsChangedIfShareExtensionWasUsed() {
         if let userDefaults = UserDefaults.shared, userDefaults.bool(forKey: UserDefaults.hasExtensionAttemptedToSend) {
             userDefaults.removeObject(forKey: UserDefaults.hasExtensionAttemptedToSend)
@@ -421,7 +417,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         logger.info("➡️ Notifications: didReceiveRemoteNotification \(userInfo)")
         increaseDebugCounter("notify-remote-receive")
         pushToDebugArray("📡")
-        openAccounts(dcAccounts)
         performFetch(completionHandler: completionHandler)
     }
 
@@ -438,7 +433,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         logger.info("➡️ Notifications: performFetchWithCompletionHandler")
         increaseDebugCounter("notify-local-wakeup")
         pushToDebugArray("🏠")
-        openAccounts(dcAccounts)
         performFetch(completionHandler: completionHandler)
     }