skip to Main Content

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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. Store the needed data in UserDefaults and call it when you need to do the calculation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search