Home > Mobile >  How to determine the number of days a user has used an app using swift?
How to determine the number of days a user has used an app using swift?

Time:02-21

I want to determine the number of days a user has used an iOS app. I want to trigger an amplitude event the first to fourth days but not after the fourth day he uses it. How can I track how many days the user used the app?

CodePudding user response:

Note and count the days the user enters

CodePudding user response:

One approach is using UserDefaults to count how many times users open the app:

var userOpenApp: Int {
    get {
        UserDefaults.standard.integer(forKey: "UserOpenApp")
    }
    set {
        UserDefaults.standard.set(newValue, forKey: "UserOpenApp")
    }
}

then check the number in sceneDelegate or appDelegate, and update it:

userOpenApp // check the number
userOpenApp = userOpenApp   1 // update the number
  • Related