iOS Notification based on time of day - ios

I have published a diet planning iOS App. I've had users ask if they could have notifications pop up on there phone when it's time for them to eat a meal. For example, if they set their set their wake up time on the App at 7am, every 3 hours an alert would pop up and remind them to eat, so would be 10am, 1pm, 4pm...
Currently I have not implemented push notifications. I have been ready about iOS Push Notification Services, and I'm thinking that is there an easier way to accomplished this? Some sort of scheduled notification. I feel I shouldn't need any network integration to perform this fairly simple task. Any suggestions are welcome. thank you

It looks like UILocalNotification is exactly what you want.
From the linked documentation:
After creating a UILocalNotification object, schedule it using either the scheduleLocalNotification: or presentLocalNotificationNow: method of the UIApplication class. The scheduleLocalNotification: method uses the fire date to schedule delivery; the presentLocalNotificationNow: method presents the notification immediately, regardless of the value of fireDate. You can cancel one or more local notifications using the cancelLocalNotification: or cancelAllLocalNotifications method of the UIApplication object.

Related

local notification at different times everyday

I would like to know what is the best approach to do if I want to fire notifications for more than one time each day everyday.
I did some research and read that notifications for the next day cannot be fired unless the user opens the app the next day and updated the notification. Is that true? is there anyway I can do it without the need of the user opening the app everyday?
Thank you
You can schedule up to 64 local notifications. There is no limit on the time period; you can schedule them years in advance if you like.
That said, if you need some mechanism to schedule new notifications, even if the app is not running at all (e.g. because the user terminated it), you need a background mode for that. Fetch is probably the way to go here, as it doesn't need a special trigger. You could also send silent push notifications in order to wake the app, make the calculations and schedule the new notifications.

UILocalNotifications algorithm

I have a problem scheduling UILocalNotifications.
My case is this: when user selects motivation category there is a dialog screen where he selects how many times in a day, week, month, motivation message should be presented to him. Then he selects time period: a day, week or a month. A motivation category has messages, and every category has different number of messages.
So my question is: how should i schedule those notifications? Main problem i think is that there can be more than one category. Can someone tell me how to do this?
I know that i cant schedule more than 64 notifications, so i cant schedule all notifications when category is selected. And i know i could reschedule notifications in
application:didFinishLaunchingWithOptions:
or
application:didReceiveLocalNotification:
I hope i have been clear about my problem.
First write a function that manages the local notifications
that is it has to check if there are 64 notifications scheduled if not then you may add some notification.(you have to handle DB part well for example setting the flags correctly)
Call the function in application:didFinishLaunchingWithOptions: just in case some notifications are expired or missed
You have to call the function in all the places where local notification is handled.
The user taps a custom action button in an iOS 8 notification.
In this case, iOS calls
application:handleActionWithIdentifier:forLocalNotification:completionHandler:
You also get the local notification object, so that you can retrieve any information you need to handle the action.
The user taps the default button in the alert or taps the app icon.
The system launches the app and the app calls its delegate’s method, passing in the local notification object
application:didFinishLaunchingWithOptions:
The notification is delivered when the app is running in the foreground.
The app calls the UIApplicationDelegate method
application:didReceiveLocalNotification:
Reference1:
Reference2:
I hope this helps.
If it doesn't cover your problem feel free to ask doubts
It works as pool when you utilized all your available notifications then you need to reschedule the free notifications in
application:didReceiveLocalNotification: but every time you are gonna reschedule you can find next notification to user that could be in today, tomorrow. Whenever you are in application:didReceiveLocalNotification: findout when to notify next and schedule.

Cancel Local Notifications after app is unused for a certain period of time

I am wondering if it's possible to do what the titles says. I have an application that has a refill reminder to refill your prescription drug via local notifications. I have seen that some apps (pill reminder apps mostly) push a notification if you have not taken your pill, or have not answered back to that notification, and was wondering if I can do the same if a user doesn't open/interact with the app after a certain period of time.
I have not began implementation but have thought about this thoroughly. What I am thinking of doing is having some sort of flag when the app is opened that removes that local notification and sets a new one once the app has gone in the background/inactive. The local notification would be set to three months from when the app has gone in the background/inactive. The question then becomes, how do I handle canceling all notifications after this notification has been received, regardless of whether the user opens the app at that notification or not?
If the user opens the app on that notification, I can have a check the method application:didReceiveLocalNotification and then handle the case where that local notification has been set and then use [[UIApplication sharedApplication] cancelAllLocalNotifications]
But if the user does not tap or open the app, how can I check and cancel all local notifications?
Sorry if this is a bit long or worded weirdly (sorry not good with words and explaining things). Let me know if you need more info or better explanation. Thanks in advance!
If I understand your question correctly, you want to know how to keep notifications from repeating when the user does not respond to a notification by opening your app.
You might consider configuring your local notification not to repeat. Instead, you might reschedule notification batches each time the application is launched.
Alternatively, if your application has a server-side component, you can use push notifications on iOS 7+ to wake your app, briefly. There is no equivalent to this behavior using UILocalNotification.

Cancelling local notification on specified date

I have problem with even inventing the posible solution for this problem.
My app needs to crate some objects of UILocalNotification with interval but if I set interval to be NSMinuteCalendarUnit if will bother me every minute until I cancel this notification in UIApplication or crash my phone with hammer...
But I'm setting in my app an end date for my project and I want those notification to work only to a specified date. Someone told me to check it when the app launches (not a problem but what if I set this notification to be fired every minute and I won't close my app during this time?). I need something independent and I want to know how to do this.. Any ideas?
You could check if you need to cancel the local notification in receiving one when you app is running and on the start up of you app.
When your app is running in the foreground and a local notification is fired for you app the application:didReceiveLocalNotification: is called on your App delegate.
There is not end date for local notifications thus the only way you can cancel then is from you app when it is running.

Push Notification that cancels or reschedules a Local Notification?

We're investigating building an alarm-style iOS app as an extension of a website.
We plan to have alarms sent to the device via push notifications. We want to also have a local notification set to a time that's a little after the planned push notification just in case of no network connectivity and the push notification does not reach the user.
However, we would like to cancel this local notification and re-schedule it when the push notification is received so it doesn't annoy the user with an unnecessary notification.
Essentially two types of push notifications:
The actual alarm if it's set to be sent (normal ability)
No alarm but reset the local notification to a little after the next planned alarm time (unknown ability)
Is this a possibility?
Maybe with work-around such as being able to remain in the background like an audio app that only handles the push notifications and we could ask Apple for special approval?
How common it is to get special approvals like this?
Thanks
I'm not sure, like Anthony Corbelli, what the reason for the push notification is if you're going to have the local notification set up for the same alarm.
In any case, if you want to cancel and/or reschedule an existing UILocalNotification from within the push notification handler, you can get a list of notifications with
[[UIApplication sharedApplication]scheduledLocalNotifications]
and then cancel the one you want with
[[UIApplication sharedApplication]cancelLocalNotification]
You can then modify the notification as desired (e.g., move its fireDate into the future) and reschedule it as appropriate.

Resources