我在XCode 8中工作。我的主要故事板中有三個ViewController。前兩種是介紹屏幕,可以解釋應用程序的功能等等。iOS:在應用程序已被使用之前跳過ViewControllers
是否有方法檢查用戶是否已經在某個時間範圍內打開了應用程序(例如「今天」),如果是,跳過前兩個屏幕?
(用戶無需與帳戶或東西登錄。)
我的應用程序的方法是這樣的:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool {
//Requesting Authorization for User Interactions
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
// Enable or disable features based on authorization.
}
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
let userDefaults = UserDefaults.standard
let calendar = Calendar.current
if let lastOpened = userDefaults.object(forKey: "lastOpened") as? Date, calendar.isDateInToday(lastOpened) {
// app has been opened today
let myViewController = ViewController()
window?.rootViewController = myViewController
} else {
// app has not been opened today/not been opened at all
print("Alright, opening explanation screens")
let myViewController = StartViewController()
window?.rootViewController = myViewController
}
// save the current date for the next check
userDefaults.set(Date(), forKey: "lastOpened")
userDefaults.synchronize()
window?.makeKeyAndVisible()
return true
}
你必須拯救'Date'成'NSUserDefaults'並檢查是否'今天Date'等於在''AppDelegate'和didFinishLaunchWithOptions'改變'window.rootViewController'的你喜歡的方式。你最好自己編碼,這會很有用。 – JuicyFruit