我有一个只需要弹出一次的条款协议,但是每次启动该应用程序时都会弹出该协议,我如何才能使其只弹出一次,并且当按下该按钮时,同意永远不会再次弹出,除非删除并重新下载了该应用程序。我正在尝试遵循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()
        }
    }

}


我的同意功能是警报控制器

最佳答案

我忘了同意()后添加

UserDefaults.standard.set(true, forKey: "Walkthrough")

关于ios - UIAlertView只显示一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44124053/

10-14 23:14