I was playing around with notifications on iOS. How do you think Due implements persistent reminders? If a reminder is overdue it will remind every 5 minutes until marked as done. Here are some potential strategies:
They schedule a local notification with UNCalendarNotificationTrigger repeats:YES. I don’t really understand how this API works. I don’t understand how I could schedule a trigger for 25Dec and repeat every minute. I’m actually pretty sure it’s impossible to set a repeat of every 5 minutes with UNCalendarNotificationTrigger. This was the best explanation I could find on how triggers work but even then it’s just confusing?
Schedule only the first notification and then recursively schedule the next notification for this reminder. This would work great with willPresentNotification except this will only work when the app is in foreground so I can’t see how they could do this.
Schedule all the individual notifications on each 5 minute interval up front. There is a limit of 64 notifications so it seems like a poor strategy as a background task of some kind would have to be scheduled to run. If the background task never runs at the discretion of the OS, notifications will stop firing. Notifications firing is critical to the app, so surely this can’t be the strategy?
Remote notifications. Would work but won’t work offline.
Related
I'm currently working on an alarm application , and i am implementing a smart alarm feature where i have to fetch data from server to determine whether it is the right time to wake user up.
Let's say, the case is :
Alarm set to 06:30AM
Smart alarm feature set to 30 mins before 06:30 , which the data fetching will happens 5 times with 5 minutes interval starting from 06:00AM to 06:25AM
If , let's say , at 06:15AM the server returned a data which is needed to wake the user up, all tasks scheduled will be cancelled immediately
Current time is 11:30PM
No smart alarm's tasks will be executed during the period of 11:30PM to 06:00AM
You can use Push Notifications / Silent Push Notifications to achieve this task.
Please note the user must opt-in for push notifications for this to work.
Here is an overview of how you can achieve it
Whenever user set's an alarm send this time to server via a web-service.
The server will send a push notification payload to APNS and it will redirect to App based on device token.
Once the device receives notification payload a delegate will be called. You can process the data in this payload related to alarm or invoke a web service call.
Use beginBackgroundTaskWithExpirationHandler to execute your 5 minute interval tasks. beginBackgroundTaskWithExpirationHandler request extra time from the OS to execute a task. It is not specified (intentionally) by Apple how long this extra time is, however in practice it is around 10 minutes.
Please read more in detail about: Push Notifications, Silent Push Notifications & background task handlers.
Background Fetch API : In iOS 7, Apple added support for background fetch—a kind of smart, per-app crontab that wakes up at opportunistic times. There is no way to force background fetches to execute at exact intervals. iOS checks how much data and battery power was used during previous background fetches when scheduling future callbacks.
Adding support involves editing your application’s property list (see UIBackgroundModes) and setting a fetch interval early in the app lifecycle
More Details Here
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.
iOS guidelines apparently don't allow to use background tasks for more than 10 minutes. I am designing a cooking timer app that allows the user to set a specific time and begins a count down.
However it appears impossible to set a background task (e.g. using UILocalNotification or adding an NSTimer to [NSRunLoop mainRunLoop]) that runs for more than 10 minutes.
Is there a work around this? How do developers designs apps that trigger timers that last longer than 10 minutes?
Possible solutions:
A: use server service and run the timer remotely, push notification from server once timer finishes to "warn" user. Cons: expensive to run server, time costly to develop.
B: once the app starts keep it active in the foreground (don't allow the screensaver to trigger). Cons: battery expensive.
Any other ideas?
EDIT: I would like the app to work with iWatch. Hence displaying a glance notification on iWatch once the timer should trigger. As this is guided by the iPhone app I would not be able to do so unless the app is active.
The documentation for UILocalNotification says:
A UILocalNotification object specifies a notification that an app can schedule for presentation at a specific date and time. The operating system is responsible for delivering local notifications at their scheduled times; the app does not have to be running for this to happen.
So, this limit of running apps no more than a few minutes in background does not apply with notifications (as the app doesn't have to be running).
For more information, see the Local and Remote Notification Programming Guide.
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 :)
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).