简体   繁体   English

我如何知道iPhone日期日历中的日期是否更改?

[英]How do I know if day is changed in iPhone date calender?

As I know, we can identify if time is changed in iPhone settings by using this method 据我所知,通过使用此方法,我们可以确定iPhone设置中的时间是否已更改

- (void)applicationSignificantTimeChange:(UIApplication *)application

but I want lines which will fire condition if day is changed. 但我要更改日期的行会触发条件。

eg Today is 10 Mar 2014, but later if I physically changed day like 11 Mar from my iPhone setting, then I wanted to know the same in above method. 例如今天是2014年3月10日,但是后来如果我从iPhone设置中更改了3月11日这样的日期,那么我想知道上述方法中的相同内容。

Anyone please help. 有人请帮忙。

Thanks in advance. 提前致谢。

I would suggest that you save off the current date each time your app starts and each time your app becomes inactive or goes into the background. 我建议您每次启动应用程序,每次应用程序变为非活动状态或进入后台时都保存当前日期。

Then when applicationSignificantTimeChange: is called, check the current date with the saved date to see if the day has changed. 然后,当调用applicationSignificantTimeChange:时,将当前日期与保存的日期一起检查以查看日期是否已更改。

I just tried it, and UIApplicationSignificantTimeChangeNotification does fire when you manually change the date through system settings–not just when the date changes after midnight. 我刚刚尝试过,当您通过系统设置手动更改日期时, UIApplicationSignificantTimeChangeNotification确实会触发,而不仅仅是午夜之后更改日期。

So you don't need to do anything more for manual date changes, applicationSignificantTimeChange will be called. 因此,您无需为手动日期更改做任何其他操作,将调用applicationSignificantTimeChange

And if you really need to enforce that action is taken only if the date does change, then of course you can store the date that you were last aware of and do a comparison in your implementation of applicationSignificantTimeChange to prevent unneeded execution if, for some reason, the event fired but the date hasn't actually changed. 并且,如果您真的需要强制执行仅在日期确实发生更改时才采取的操作,那么您当然可以存储上次知道的日期,并在applicationSignificantTimeChange的实现中进行比较,以防止由于某些原因而不必要的执行,事件已触发,但日期实际上并未更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM