Schedule next UILocalNotification if app is not running - ios

I am working on an app for a trash company. The idea is as follow:
There is a calendar for 2012/2013 with dates when and what trash can (brown, gree and black) will be picked up.
I need to make a kind of notification system which will send a notification on a specific day (from that array) with some text about what container will be picked up this week.
That would not be smart to post all notifications at once coz there are over 100 (and I've heard the limit is 64 in iOS).
I thought to schedule next notification after the current one fires. This could be done in the kind of handleNotification method when user touches the action-button at the notification and goes to the app. But what if the user gets enough information from the notification window and never touches that notification, never goes to the app and mostly have it in the "non running" state at all?
How to schedule next notification then?
Maybe some smart heads can come with other ways to make it works without using UILocalNotification?

There is no way.
If the user never opens up your app you will at most have 64 scheduled notifications. When all those have been triggered there will be no more notifications.
Although you can have your notifications repeating. So if the brown trash can will be picked up every week you can set a repat interval of weekly instead of scheduling it 52 times (thus saving 51 notifications).

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.

iOS Notifications. Which one to use?

My calendar app is not connected to Event Kit which allows me to create custom repeating intervals like "every 3 days, 29 times" etc.
Now i would like to add Notifications to my Events ... but my custom repeating events are limiting me in every possible way.
I think I have checked every possible solution:
UILocalNotification
UILocalNotification is limited to 64 events and NSCalendarUnit's in-built Unit Time Intervals aren't very flexible.
1 event repeated every 2 days will fill this up very quickly
Should i reschedule 64 Notifications on every app start and beg the user to start the app regularly? Not running the app for a while will not reschedule notifications.
Event Kit (Calendars & Reminders)
I could create a calendar or Reminder list, generate single events from the custom repeating events and add notifications here. But the user can edit this, which will cause confusion.
I can't synch this back to my app.
Should i create a calendar or reminder list for Alerts and hope that the user will not touch this?
Apple Push Notification Service
Everywhere i can read: They are not reliable! There is no guarantee that push notifications will actually be delivered, even if the APNS server accepted them.
I think push notifications are not made for notifying the user at scheduled times as there is no guarantee they will arrive.
The question is what should i do, or what would you do in my case? No solution is perfect and i am hoping to find the most user friendly approach here. In case i am missing a approach, i would like to hear the alternative.
Edit:
Adding a another method for completeness.
UILocalNotification without repeats
don't offer the repeating of local notifications. The user can assign single Notifications to a event. After enabling the 65th notification, a popup will remind him that he has reached the system limit. This way you put the responsibility to the user. After reaching the limit he will be forced to focus on events that are not far in the future.
You could save all your events to core data and then every time the app is launched or when your main view appears load in all events for that week and set a scheduled local notification. Once the event is scheduled you set a flag in the entity eg hasBeenNotified.
Hope it helps.
I decided to offer local notifications without repeat functionality.
This decision was made after chatting with a few users.
Better to offer something than to offer nothing :)

iOS - UILocalNotification - can schedule only up to 64 slots at a given time

Overview
I have an iOS app which sends local notifications at specific dates.
I just learned that I can only schedule 64 notifications at a given time.
There are cases when I can't schedule notifications as the 64 slots are filled.
So I store them in the database and when the user responds to a notification I check if there are any available slots and schedule the remaining notifications.
Problem
When the user doesn't respond to a notification my code is not executed so I am not able to schedule the remaining notifications.
Question
Is there a solution for this problem ?
can I execute a piece of code (house keeping) at certain times ?
is there any work around for this ?
You may not want to signal to the user there is a problem, but rather just do it in the background. If a user has 64 notifications for one app and hasn't opened the app, then they probably aren't using the app. Once a notification has fired it isn't in the array anymore. So you will have room every time a notification is fired off. They do however remain in notification centre, which you have to clear out yourself.
Its usually better to not present possible problems to the user, but rather handle them in a way that makes sense internally if that is an option. Look up the delegate methods for the appDelegate and you will most likely find ways you can handle what you are trying to do.
Thought I would make a post in case you wanted to accept the answer.
Best of luck.

Resources