[英]What is the most effective way of tracking time/dates in an iOS/Swift application?
I am building an iOS Swift habit-building application that needs to send push notifications to the user at certain user-specified time intervals and/or dates. 我正在构建一个iOS Swift习惯建立应用程序,该应用程序需要在某些用户指定的时间间隔和/或日期向用户发送推送通知。
For example, user one creates a new habit. 例如,用户一个养成新习惯。 They specify how long they want it to last, which days they'd like to do it, the time of the day to perform the task, etc. The start time is the day they create it.
他们指定希望其持续多长时间,想要执行的日期,一天中执行任务的时间等。开始时间是创建它的日期。 The user receives push notifications at the time they are supposed to perform a task.
用户应该在执行任务时收到推送通知。
I am curious what the most effective method (efficient with memory, etc.) would be to implement these reminders, and track the timing of the habit in relation to the date. 我很好奇,最有效的方法(可以有效地记忆)等是实现这些提醒并跟踪与日期相关的习惯时间的方法。
Is NSTimer the most elegant solution to this? NSTimer是最优雅的解决方案吗? Does NSTimer run in the background, which I've read is a memory intensive solution?
我读过的NSTimer是否在后台运行,这是内存密集型解决方案?
I am certain this question will be downvoted, however I have been doing research and trying to find a clear answer for a good starting point on this. 我确定这个问题将被否决,但是我一直在进行研究,并试图找到一个明确的答案,以此作为一个好的起点。 This is my first iOS/Swift application.
这是我的第一个iOS / Swift应用程序。 Thank you for your help.
谢谢您的帮助。
A regular timer will not run in the background. 常规计时器不会在后台运行。
You would want to either be using a backend service to send push notifications, or scheduling local notifications using UNUserNotificationCenter by creating a UNNotificationRequest . 您可能想使用后端服务发送推送通知,或者通过创建UNNotificationRequest来使用UNUserNotificationCenter调度本地通知。
I think you can realize it through local notifications. 我认为您可以通过本地通知来实现。 when user set up the days/time they want to perform the task, just create a push notification for each time.
当用户设置要执行任务的日期/时间时,只需为每次创建一个推送通知。 Hope it helps...
希望能帮助到你...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.