這很簡單
您需要在UserDefau中保存狀態LTS當用戶成功登錄這樣的:斯威夫特3,4]
/// call if user logged in
func saveLoggedState() {
let def = UserDefaults.standard
def.set(true, forKey: "is_authenticated") // save true flag to UserDefaults
def.synchronize()
}
然後在AppDelegate中的didFinishLaunchingWithOptions還真
let def = UserDefaults.standard
let is_authenticated = def.bool(forKey: "is_authenticated") // return false if not found or stored value
if is_authenticated {
// user logged in
let homeController = HomeController() // create instance of HomeController or from Storyboard
window?.rootViewController = homeController // change rootViewController to HomeController
window?.makeKeyAndVisible() // show window
}
之前,您可以只保存在userDefaults一個布爾變量和每個他們打開應用程序時,檢查該變量是否爲真。如果它是真的,請將用戶移動到家庭控制器 – Martheli