我在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