How to detect Apps first launch in iOS?

前端 未结 7 932
小蘑菇
小蘑菇 2020-12-01 06:11

I would like to display a welcome screen when a user opens my app for the first time. What method is there to check the first launch of an app in Swift?

7条回答
  •  悲哀的现实
    2020-12-01 06:30

    Swift 4 and higher

    You can use this anywhere to verify that the user is seeing this view for the first time.

    func isAppAlreadyLaunchedOnce() -> Bool {
        let defaults = UserDefaults.standard
        if let _ = defaults.string(forKey: "isAppAlreadyLaunchedOnce") {
            print("App already launched")
            return true
        } else {
            defaults.set(true, forKey: "isAppAlreadyLaunchedOnce")
            print("App launched first time")
            return false
        }
    }
    

    Note: This method would return false after user re-installs app and launch first time.

提交回复
热议问题