我正在尝试弄清楚如何在用户达到目标后弹出警报。但是,我只希望它在触发后每天显示一次。提前致歉。如果我的逻辑不适合解决这个问题。
// Check to see if hydration goal has been reached
if (waterCups >= dailyHydrationGoal) {
// User has reached goal
if (alert has not been fired yet today) {
// alert pop up you reached your goal!
}
}
我将如何确保它每天只启动一次?
您可以使用 isDateInToday:
检查给定日期是否在“今天”的方法。
NSDate *lastAlertDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey"lastAlertDate"];
if(![[NSCalendar currentCalendar] isDateInToday:lastAlertDate]){
//Show alert
NSDate *today= [NSDate date];
[[NSUserDefaults standardUserDefaults] setObject:today forKey"lastAlertDate"];
}
关于ios - 如何每天显示一次警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44853326/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |