Handle multiple remote notifications while app is active - swift - ios

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.

Related

IOS/Android app custom push notification handling

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?

Control which iOS notifications to display

We have iOS push notifications configured and running. However, we would like the user to select which categories are interesting to receive and which are not important and would like to omit receiving those notifications.
Is there any way to do this through Apple push notification itself rather than through the server sending the notifications? (We can change the sent JSON). Can the iPhone send which categories it would like to receive and which are not needed by registering them to Apple? Other choice, can we interrupt the push notification before being shown and decide whether it should be shown or not through a delegate? So far, I can't find an available method to do either.
Any help is appreciated
The short answer is not from the client side. If you want a solution that works 100% of the time you will need to do something on a server which only sends the types of push notifications the user subscribes to.
If your App is in background there is no concept of "categories" of PUSH notifications and you have no control over if they show up in the notification center.
You can examine inbound push when the App is in the foreground and decide on the basis of some meta data to display or not, but that is not a 100% solution.

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 Local Notifications with an API call

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?

iOS - Ask to enable push notifications after initial decline

I would like to know if it's possible to force the "XXXXX would like to send you push notifications" popup from within an app, after an initial decline. The use case is as follows:
The user installs the app, gets the alert about push notifications,
and declines because they don't know/trust the app yet.
They use the app and proactively request within the app to be alerted
when something happens (say for example something they want to buy is
sold out so they want to be alerted when it is back in stock).
So now the user has asked the app to notify them about something
specific but has push notifications disabled at the operating system
level.
So if the user requests an alert, but I detect that they declined
alerts on first run, I need to notify them of this and have them turn
push notifications on for the alert to work.
Ideally, I would like to force the "XXXX would like to send you push
notifications alert" at this point (a second time since they
installed the app).
I guess plan b would be to show them my own message telling them they
have to go into their system settings and turn it back on manually in
order to receive the alert they want. This is far from ideal.
Any help would be appreciated. Thanks.
You can't make iOS show the alert again. Here's a better approach:
Keep a flag in your NSUserDefaults indicating whether you should register for push notifications at launch. By default the flag is false.
When you launch, check the flag. If it's true, register immediately. Otherwise, don't register.
The first time the user does something that would cause a push notification, register for push notifications and set the flag in NSUserDefaults.
This way, when the user gets the push notifications alert, he has some idea why he's getting it, and might actually say yes.
I am also facing a similar kind of issue. After searching so much, I decided to do what you call Plan B. That is, show the user my own alert saying that push needs to be enabled for better experience, or something like that.
To check that required push types are enabled, use this method:
- (UIRemoteNotificationType)enabledRemoteNotificationTypes
UIApplication reference
I think that this is the clean solution. Consider a case where after accepting the request at first, the user turns off push, this thing will work even in that scenario.
The best way to do it would be to (if you're making a game) ask them a preemptive question (e.g. Do you want us to notify you when your crops are ready to be harvested? -Yes -No), and when they answer "yes", then fire the native iOS push popup. then you can layer in multiple questions along the user funnel, and you'll eventually catch them all.

Resources