I am trying to create a local notification with the following requirements:
The user sets the days of the week for the notification
The user selects the time of day for the notification
The message of the notification requires calling an API to get the content.
For example, the user wants to know what the traffic is like on their commute every weekday at 0800.
There are some great tutorials on creating Local Notifications (like this one Adding Local Notifications in Your iOS App - appcoda), but I would like to know if I can make an API call to populate the message of the notification.
So rather than having an annoying "Check out the traffic now" notification which can quickly direct the user to the relevant page in my app, I would like to have: "There is minor congestion on the {road}" or "The roads look clear right now"
Is this at all possible? Thanks.
EDIT: Post iOS7 release
So it seems we have;
Background Fetch - able to fetch the new content and keep the content up-to-date
Remote Notifications - able to download the content when the app receives the push notification
Neither of these work in my scenario. I need to make a call as close to the user's specified time as possible. With background fetch, it is no use if the last update was at 5am when the roads were probably clear. Remote notifications are not ideal either as I am not pushing a notification, I would be displaying a local notification.
Does anyone know of a clever workaround to achieve this solution?
Related
We want to add a feature to our app so that users are able to opt-in to being reminded to read important notifications which they might have missed. Here's how we would like it to work:
When a push notification comes in, a Notification Service Extension triggers.
The extension checks to see if it should do any work (we don't want to remind users if they are currently in the app).
If reminding is enabled, the extension attempts to spawn 3 local notifications at 1-minute intervals reminding the user that they have missed important information.
If the user opens the app, all existing local notifications are cleared.
If another notification arrives before the user opens the app, any existing local notifications are cleared and a new set are created.
This works great, except for step #3. I check notification authorization from within the service extension before I do work and am consistently getting .authorized back. However, when I call UNUserNotificationCenter.current.add(_:withCompletionHandler:), the completion handler is invoked with a UNError: Notifications are not allowed for this application.
What's odd is that it works sometimes. For example, I'll get the 2nd notification through and get the reminder for it, but the 1st and 3rd fail. However, this is exceedingly rare (< 5% success rate scheduling local notifications).
Does anyone have any insight into this?
I want to develop an app, but before I actually start developing, I've been doing some research so that i can be sure it's going to work in the way I'd like to do this.
You can imagine the app as a kind of news app, where the user can indicate whether he wants to receive push notifications, and may also indicate that he only wants to receive a push notification if it is in X distance from his current location.
And this is probally a problem on IOS, On android it would be no problem if a push notification came in to read the current position of the user and settings and then show the push notification or not.
As far as I've read this is a problem on iOS, the system receives the push and the app can not respond to it unless the user clicks on it.
Theres also another problem about closing an app on IOS, ideally a app should not be closed (swiped out) by the user because this would be a force close on IOS.
From ive seen most users still swipe out apps, and this would mean that my app cannot run background tasks anymore.
This is what i thougt about:
Send Silent push, app download data on the background -> Check if this meets the user settings, if so show a local notification. (30 sec time to handle, but do not know if it is possible to throw a local push here too.)
The app sends data on the background over the user's current position before sending a push, the server checks for which apps it should be sent (actually no solution, too much data usage as it may be that the user is only one Specific location, need a good server if the app is used on thousands of devices.).
Does anyone have any idea how to handle this problem?
I would like to know the workflow to handle multiple remote notifications received at the same time while the app is active (opened, running ..).
The best option for me would be to display the notification in the notification center but I heard it is not recommended by Apple, is there someone who already did it without having problem during the submission ?
The second option would be to handle all these notifications, display an alert for the first one, and then ... I don't know how to handle the second one, third one etc ..
EDIT: The thing I'm trying to do is to not spam the user with alert if for example if he receives 45 notifications in one minute, then I would like to display every notifications in the notification center (where all notifications of all applications are displayed, I'm not sure about the name), and each time he clicks on one notification, I could display the alert or display the right screen etc, do you know if this is possible ?
Thank you for your help.
I have 8 medicine local notifications which differ from day to day.
They work fine for one day but I want to fire them everyday. I used BackgroundFetch to reschedule the local notifications every time fetch is executed. But my problem here is that background fetch depends on how often the user uses the app. What if the user doesn't open the app more often Also I didn't want to implement silent notifications because it will not wake up the app if the user does not have internet connection. what approach should I use instead of background fetch?
EDIT:
I also thought about location updates in background because my notification times are taken from location of user and calculated accordingly. But will this consume a lot of battery?
Since I've got the same issue in an
app that probably does the same stuff as yours, I'd like to share my solution.
It comes with one compromise works only from >=iOS8.
By using an interactive notifications you can reschedule your notifications in background, of course the user need to interact with the notification, but I think that if you different actions instead of open the app or cancel the notification is possible to have more interested user.
It's all about creating a configuration with actions.
Here you can find a tutorial.
I would like to know whether there is an alternative different than what I am thinking so far. I have an ios app, which gets data from my server, when the user clicks refresh button or so.
Now, I want to send data from server to the app - for example when an event started so as to update the label on that event.
I have thought of the following :
Use background fetch from my IOS app and connect to the server every an interval
Send a push notification and make the user open the app, and the app calls refresh
Is there any other way? Is it possible that server will send the data (just like a push notification) but without the notification to be visible, without firing the app, I just want to change some of its data - an approach similar to the Google Cloud Messaging for Android.
To visualise what I am saying, if you have used LiveScores app, it updates for example the minute of a live match - I want something similar.
I guess I need to follow approach 1, with background fetch (which became more effective in ios7) but just out of curiosity if there is any other solution out there.
Thanks
Under ios7+ you can do silent pushes (which aren't displayed) [see a nice tutorial — hayageek.com: iOS Silent Push notifications]
Under ios6 and below you are of of luck