浏览代码

added TabBarRestorer to store and restore last active tabs in user defaults

nayooti 5 年之前
父节点
当前提交
f2ae5d2674
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      deltachat-ios/Handler/TabBarRestorer.swift

+ 16 - 0
deltachat-ios/Handler/TabBarRestorer.swift

@@ -0,0 +1,16 @@
+import UIKit
+
+class TabBarRestorer: NSObject, UITabBarControllerDelegate {
+
+    private let userDefaultKey = "last_active_tab"
+
+    func restoreLastActiveTab() -> Int {
+        return UserDefaults.standard.integer(forKey: userDefaultKey)
+    }
+
+    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
+        let activeTab = tabBarController.selectedIndex
+        UserDefaults.standard.set(activeTab, forKey: userDefaultKey)
+        UserDefaults.standard.synchronize()
+    }
+}