How to detect Apps first launch in iOS?

前端 未结 7 911
小蘑菇
小蘑菇 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:25

    Try this for Swift 2 and below

    func isAppAlreadyLaunchedOnce()->Bool{
        let defaults = NSUserDefaults.standardUserDefaults()
    
        if let isAppAlreadyLaunchedOnce = defaults.stringForKey("isAppAlreadyLaunchedOnce"){
            println("App already launched")
            return true
        }else{
            defaults.setBool(true, forKey: "isAppAlreadyLaunchedOnce")
            println("App launched first time")
            return false
        }
    }
    

提交回复
热议问题