I have a terms agreement that needs to pop up only once, however it is popping up each time the app is launched, how can I make it only pop up one time and when pressed agreed to never pop up again unless app is deleted and redownloaded. I am trying to follow How can I show a view on the first launch only?
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if !UserDefaults.standard.bool(forKey: "Walkthrough") {
UserDefaults.standard.set(false, forKey: "Walkthrough")
}
}
}
class FirstViewController: UIViewController, UIAlertViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if UserDefaults.standard.bool(forKey: "Walkthrough") {
print("already shown")
// Terms have been accepted, proceed as normal
} else {
agree()
}
}
}
my agree function is an alert controller