简体   繁体   English

在iOS / Swift应用程序中跟踪时间/日期的最有效方法是什么?

[英]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.

相关问题 在Swift中迭代日期范围的最有效方法是什么? - What is the most effective way to iterate over a date range in Swift? 此iOS应用最有效的工作流程是什么? - What is the most effective workflow for this iOS app? 在iOS中追踪时间的最有效/最精确的方法是什么? - What's the most efficient / most precise way to track time in iOS? 使用数据,iOS,Swift 3刷新表的内存效率最高的方法是什么? - What is the most memory efficient way to refresh table with data, iOS, Swift 3? 在 Flutter 中管理 IOS 和 Android 的推送通知的最有效方法? - Most effective way to manage push notifications in Flutter for IOS and Android? 在iOS应用程序中查看多页PDF的最优雅方法是什么? - What is the most elegant way to view a multipage PDF in iOS application? 仅使用Mac在Xamarin上部署iOS应用程序的最经济有效的方法? - Most cost effective way to deploy iOS app with Xamarin with only a Mac? 一次登录iOS-最有效的方式? - One time login in iOS - Most Efficient Way? 在iOS上显示CVImageBufferRef的最有效方法是什么 - What is the most efficient way to display CVImageBufferRef on iOS 在iOS中作为背景的视频最有效的方法 - Most effective method for video as background in iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM