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.
Related
I am looking for solution to get data in background mode even app is terminated.
There are lots of tutorials and answers available for this questions, but my questions is different than other. I haven't find any proper solution on stackoverflow, so posted this question.
I have scenario which I can explain. I'm using realm database which store event date, name, time, address etc. Now the thing is that, I want to write a code which are execute in background, In this code I want to get all event data and compare their date with today's date. And based on days remaining between these days fire local notification to remind user about how many days are remaining for specific event.
I want to call this background fetch method exactly 8 AM in local time everyday.
I haven't write any code due to confused with Background fetch and implementation. Can anyone know how to implement this ?
Help will be appreciated.
I have got solution to fix issue. As per I have talked,
I want to write a code which are execute in background, In this code I
want to get all event data and compare their date with today's date.
And based on days remaining between these days fire local notification
to remind user about how many days are remaining for specific event.
So, when I getting response from API, I'm creating local notification for all events with unique id, which are fire and repeat daily at specific time, where I have display event time and remaining days of event.
Apple documentation states that there is no guarantee when background fetch is performed. It's up to the system to decide.
The system waits until network and power conditions are good, so you should be able to retrieve adequate amounts of data quickly.
The guaranteed way to wake your app is to send at 8 am VoIP push notification from the server. It is guaranteed that the app will be wakened upon receiving a push, and you'll be able to execute the jobs you need. For more details, https://medium.com/ios-expert-series-or-interview-series/voip-push-notifications-using-ios-pushkit-5bc4a8f4d587
It is not possible to wake up the app from suspended mode in iOS except with push notification (for this server has to send push notification).
This is something which is not documented anywhere. IMHO and experience with iOS, Apple must be recording user activities since the start of the iOS era. ScreenTime is a product of those recordings only that apple was able to create and visualize the data to present a user facing app that very beautifully restricts, manages and displays your activities. In WWDC 2018, it was even quoted that apple will even detect, if the user opens your app at let's say 9 PM daily before going to bed, iOS will allow every possible resource (battery, internet, processing time etc) to that app at 9 PM. But you need to understand your user activities before you do this. Let's take an example of:
News App:
A majority of users would check the news in the morning (If they are not instagram addicts). At this time even apple should be biased to open your app with background fetch. Unless of-course there is too much of a resource crunch
A Game: Many games allow provide a restriction time by calling it "recharge" or "re-fill" the energy of a character before user can play another round. This is done so that the addicted person would buy gems to remove that restriction and hence monetize the idea. But if you know that the refill process is completed before 8:00 AM in the morning or user plays your game daily at 8:00 AM configure background fetch accordingly.
Background fetch works with interval rather than specific time.
// Fetch data once an hour.
UIApplication.shared.setMinimumBackgroundFetchInterval(3600)
Lastly why don't you try silent push notifications? Based on your question, I think silent notification is enough to wake your app after a push notification from the server, download some data and do your calculation and provide a local notification.
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.
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.
I'm creating an app that needs to fire local notifications for sunrise and sunset on a daily basis.
Sunrise and sunset times changes every day.
I want the registering of the local notifications to take place even if the user didn't open the app (i.e. a background task). So the user installs the app, sets his location (since sunrise and susnet calculations are location based) and then he knows he'll get notifications for sunrise and set every day without needing to open the app or being connected to the internet.
Ideally I need a background task for registering local notifications over a given period which runs at least once every period. "e.g. registers local notifications for the next week, which in that case I need it to run at least once a week".
None of the current background modes fit my case, I tried a background fetch, but since there're no data downloaded iOS stopped running my background task after a couple of days
I know I can use push notifications, but I don't want to unless it's my last option, cause I want the notification to take place even if the phone was not connected to the internet.
So how do you think I can tackle this? Is there something I'm missing?
Get Location for every ānā minutes in background. By Using beginBackgroundTaskWithExpirationHandler and NSTimer .it keeps app live in background.
So, You can schedule a localnotification in background.
For getting location update in background Refer the link
How do I get a background location update every n minutes in my iOS application?
(From iOS7 finite-length background task time reduced to 180 seconds. so you must fetch location within next 180 seconds.)
If user force quit the app. the app destroyed all the task . Use Significant location change or region monitoring to restart the Background task and get location for every ānā minutes.
I'm trying to get my task manager app to automatically badge the app icon with the number of tasks due today. I have tried two different solutions, but none are ideal or work exactly how I want.
Solution 1: I set up local notifications to send a notification at 12 in the morning when a task is due that day. The problems are, one, I want to badge the app AFTER the notification is sent but I can't figure out how to do that, and two, every time a new task is created or a due date on another is edited, I have to delete all scheduled local notifications and then reschedule them all. This does not seem efficient, especially because I have to sort through my core data objects to get the due dates.
Solution 2: I set up my app to refresh in the background so the icon badges update, then just updated the badge number anytime a new task or change of due date was made in app. The problems with this are that one, obviously it's kind of a waste of energy to refresh in the background when really I only need it to refresh at the beginning of the day, and two, I can't schedule when it actually refreshes.
Is there another way I should be going about this?