sharedev
sharedev

Reputation: 419

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.

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? Does NSTimer run in the background, which I've read is a memory intensive solution?

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. Thank you for your help.

Upvotes: 2

Views: 327

Answers (2)

Shan Ye
Shan Ye

Reputation: 2662

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...

Upvotes: 1

Dima
Dima

Reputation: 23634

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.

Upvotes: 5

Related Questions