I have a counter to count how many times an app is opened since I want my Google Ads to show up every 5 times an app is opened. It works well except that when the app is force closed, the counter will reset. Anyway to overcome this and save the number of app opens in counter?
Here is my code
let current_open_count = UserDefaults.standard.integer(forKey: "kAppOpenCount")
if current_open_count == 5 {
UserDefaults.standard.set(1, forKey: "kAppOpenCount")
}else{
UserDefaults.standard.set(current_open_count + 1, forKey: "kAppOpenCount")
}
} else {
//Do nothing
}
}