Konstantinos Natsios
Konstantinos Natsios

Reputation: 2924

Notification from the background

I'm currently making a TODO app and I save the date that the user has to do a thing. Let's say that he saves the date 28-7-2016 to do something, I make another column tobenotified and I take the date minus it by 1 and save it, so the user should be notified the previous day that tomorrow has a thing to do.

But what if the user has closed the app(killed it). What is the proper way to send a notification from the Realm database when the date tobenotified is equal with NSDate() / the current date?

Upvotes: 0

Views: 52

Answers (1)

marius
marius

Reputation: 7806

It's not as simple like that. Realm queries can neither match against a live-updating current date nor send notifications from the background.

You want to look into UILocalNotification and set it up with the tobenotified date as fireDate and schedule it locally. Note that you will require your users consent and have asked them initially by registering for local notification types so that you're permitted by the OS to schedule and present notifications. Also if the user can modify or delete a reminder, then you need to find a way to identify the notification via the the provided identifier and remove or re-schedule it accordingly.

Upvotes: 1

Related Questions