iOS: Limit local notifications to a certain time frame? - ios

I am working on an app that uses local notifications, which are repeating in an interval chosen by the user (between 5 and 60 minutes).
I would like to enable users to also choose a certain time frame so that the app will fire notifications only during this time frame. I was thinking about using NSDate and some kind of conditional statement where the notification only fires if the current time is in the time frame which was chosen by the user.
Do you think that will work or am I overseeing something?

You can use UNCalendarNotificationTrigger for this.
Triggers a notification at the specified date and time.
See
official documentation.
Calendar triggers can also be repeating, so it should serve your purpose.

Related

Repeating an event like in iphone reminder app

In iPhone reminder app you can set a calendar event to repeat, say, every three days after a specified date, until reaching another specified date. I am starting to create an app that should have a feature like that. My first attempt was to use local notifications, but I have not seen a way to program a trigger using date components to do that. Am I overlooking something about local notifications or date components, or are there other ways to do that?
Have you looked at UNTimeIntervalNotificationTrigger And UNCalendarNotificationTrigger?
You probably have to combine the two. Use UNCalendarNotificationTrigger for the initial event at a certain date and then UNTimeIntervalNotificationTrigger for repeating the event.

Running background tasks ending with a local notification in swift?

This is in response of an effort in order to implement an app in a way, so that I could run some code at specific interval of time i-e Morning 9:00 am daily.
Lets take an example of an Alarm.
If user is allowed to set a time interval, during which he is going to remain busy, so now after setting two - three intervals for his daily schedule.
After the app is suspended or in foreground, user needs a reminder before entering to and after getting out of the interval.
I need guidance for this problem in a way :
Local notifications for this situation in swift
Changing the mode of device from ringer to silent during that interval
OR
Accessing programatically 'Do not Disturb Me' feature of IOS
Your kind conveyance regarding this issue will be really productive for me.
Thanks.

How to send local usernotifications based on user input [duplicate]

I am creating my first app that lets the user set alerts for themselves and then the app would send the user a local notification on the set time. The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week (for example every Mondays and Tuesdays only). All the tutorials/questions that I have come across so far (like this one) have only been about scheduling the notification everyday/everyweek. The desired result that I'm trying to achieve is sort of like the iPhone's built in alarm system, where you can set an alarm to fire only on certain days of the week.
If I can't just set the notification.repeatInterval field, is there a way I can do what I'm trying to do? Could I possibly execute a little code at midnight that schedules the correct notifications for that day? If so, how could I do that?
Thanks in advance!
The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week
In iOS 10, a UNCalendarNotificationTrigger is formed using DateComponents. This means you can specify as much or as little of the date-time in question as you wish. Thus, if you specify a specific weekday and a time (hour and minutes), and nothing else, you'll repeat at that time on that day of the week.
If you also need to repeat on a different day of the week, just make another notification.

How to repeat local notifications on specific days of the week (iOS Swift 3)

I am creating my first app that lets the user set alerts for themselves and then the app would send the user a local notification on the set time. The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week (for example every Mondays and Tuesdays only). All the tutorials/questions that I have come across so far (like this one) have only been about scheduling the notification everyday/everyweek. The desired result that I'm trying to achieve is sort of like the iPhone's built in alarm system, where you can set an alarm to fire only on certain days of the week.
If I can't just set the notification.repeatInterval field, is there a way I can do what I'm trying to do? Could I possibly execute a little code at midnight that schedules the correct notifications for that day? If so, how could I do that?
Thanks in advance!
The thing that I'm having trouble with now is being able to fire the local notification on specific days of the week
In iOS 10, a UNCalendarNotificationTrigger is formed using DateComponents. This means you can specify as much or as little of the date-time in question as you wish. Thus, if you specify a specific weekday and a time (hour and minutes), and nothing else, you'll repeat at that time on that day of the week.
If you also need to repeat on a different day of the week, just make another notification.

Daily Notification

I am looking on some way to notify users with a custom message every 8 AM every day.
I need to do some data processing before I display the notification(Get the number of patients for the past 24 hours) and notify the user about the data I got using some sort of notification.
I tried to create a local notification that fires every 8 am in the morning and that is working except It is requiring me to specify it's alert message and alert body at the time of it's creation instead of on before alert show.
I am considering push notifications but I am not sure how complex this may be.
How can I accomplish that?
A hack around can be to request background fetch time from the OS. You can reschedule the notification every time the background time is allotted to you with the current number of patients in the last 24 hrs. Just compute it every time the system gives you background time.
See this article for scheduling background fetch time
You can't do what you're asking with local notifications. They 100% require static content up front. You'll need to use push notifications to do this dynamically.

Resources