Don't show push notifications - ios

Is there an opportunity to stop showing push notifications via an app?
I have an app connected to a database. When someone sends me something like a message I will get a push on my devices (lock-)screen. But if the user does not want to see specific notifications for something, maybe a new message by person XY, it should not appear!
So is there an opportunity for hide specific pushs via the app or do I have stop them server-side?

You'll have to make the change server-side. From the app side, you can't stop only certain push notifications, because it's while the app is backgrounded (or not even running) that push notifications will be showing, so your app has no control over whether specific ones will show or not.

If the app is not in the foreground then the push notifications don't get delivered to the app, they get delivered directly to the user and hence there is no chance for the app to intervene and filter them.
BUT if your app is for iOS7 only then you could use silent background push notifications, then when the push is delivered the OS will rouse your app and the push will be delivered to it, then the app can examine the content of the push and also examine the user preferences and then present the background push as a local push or not (to the user a local push looks just like a remote push).
One caveat is that if the user forcefully terminates your app (by upwardly swiping it out of the task manager) and the user has not restarted it then the OS will not deliver the silent push to it.

Related

Notify the app about remote push notification when the app is not running (terminated)

When app is not running (terminated NOT in background) and a remote push notifications is received, is there any way to inform the app about it so that the app can update something locally such as simple int counter?
I want to store something so that when the app is launched the next time, app knows that notification was received when app wasn't running and something needs to be done.
If user launches an app by tapping on a notification, obviously the app is notified about it through AppDelegate methods but these methods are never called if user launches an app by tapping on the app's icon.
To be aware of notification when user launches app by tapping on icon, i need some way to let app know that notification was received when app was in background.
There is no way you can achieve this with simple push notifications.
According to apple docs if the user has manually killed your application by swiping it out of memory, your app will never be started in the background to process data until after the user chooses to launch it again.
One solution to this problem is using VOIP push.
According to apple docs -
Your app is automatically relaunched if it’s not running when a VoIP
push is received.
But you need a strong reason for using it and apple may ask that before approving your app on the app store.
To read more about VOIP push please go through this doc - https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html
You can also be used the "Silent Push Notifications".Which are confirming that their is something available on the server, which you need to download to your app,The payload format of the Silent push notification is like
{ content-available:1 }
The Best part of the silent notification is that they do not notify the iPhone user
Here 1 is for their is something available to download from the server.
here below i have attached the apple's silent notification slide.
Your App is getting Refresh in the Background.

iOS 10 Remote Notifications When App Not Running

When I receive a remote notification I updated a counter that I save to UserDefaults and I also show a local notification. Everything works as expected when the app is in the foreground, background, and suspended states Ref. When the app is in the Not Running state my counter is not updated nor is my local notification shown.
It is my understanding that I should be able to receive and process Remote Notifications while the app is completely off. A few articles online claim that when a Remote Notification arrives while in the Not Running state that the application:didFinishLaunchingWithOptions: should be called followed by application: didReceiveRemoteNotification:fetchCompletionHandler: but in my case it is not.
Is it possible to receive remote notifications while in Not Running state?
If your app is a VoIP app and you are using VoIP pushes through PushKit then a push notification will launch your app from the terminated state in order to deliver the notification. If you are using standard push notifications then your app will not receive the notification if it is terminated. You can include an alert text with a 'silent' notification that will be displayed to the user in the event that your app is terminated in order to prompt them to launch your app.
First of all, it sounds like you have a silent notification set up. Once you add alert data to your push notification (information like the title, body etc.. you can find more on that here), it'll start to display on the lock screen.
Second, it's not possible for your application to launch from a push notification, silent or otherwise, if it's in the Not Running state. The documentation on this is actually incorrect, as it states that the application will only not be launched if the user has quit the app. However, this actually also applies for any circumstance under the not-running state, for example if your app has never been launched since installation/rebooting, or if it was quit due to memory (a fairly common occurrence - iOS purges apps which haven't been run recently as required).
did you check this mark when app is background?

Detect when app receive a push remote notification

how can I handle a remote notification without opening the app (when the banner appear on the screen)
I tried a lot of methods and they are called only when I tap on the notification
If your app needs to analyze push notification without, user tapping on it, you need to set content-available=1 in your push notification,you get the push data in 'didReceiveRemoteNotification' function in your AppDelegate. but you need to consider something, even with this method, there is no guarantee that your application get the push notification data, Your application get the push's data only when your application is in foreground or your app is in background but IOS system is not idling your application otherwise your app is not going to get the push notification from IOS.

Notification - when app is killed

I have implemented AWS SNS push notification service.
We have an issue which is explained below :
Scenario :
We are trying to save the notification message we receive as a part of requirement.
When the app is killed (swipe out from recent apps) we are able to receive notification, also we are able to save the notification message when we open the message directly from the notification panel it works fine,but when we open the app directly the notification message is not getting saved.
In short we are not able to know if we had received a notification message if we directly open the app rather than clicking the message from the notification panel.
Is this default behavior ? or is there any work around for this ?
Have looked into many posts on about Push Notifications but haven't seen any threads pointing to this scenario.
This is a normal behavior, and there is no workaround.
If your app is killed by the user, it won't be able to run ANY code before it's manually launched again.
If it's manually launched from a notification, this notification's payload will be handled by your AppDelegate.
On top of that, don't forget that Push notifications are Best Effort. That means that they are not reliable, they can be heavily delayed or never delivered at all. Don't rely on Push notifications to achieve any critical work.
If you need to keep a copy of your notifications in-app, keep them server side and fetch them as you would do with any other object.
In order to execute code when the app is killed by the user you need to implement VOIP using PushKit framework provided by apple.
VOIP push unlike regular push notification enables the app to become active even if the app is killed by user.

How to get the push notification payload when force-quit / swipe up to kill the iOS app without tapping on the banner/alert?

I’m building an app which handles notifications pushed from Parse, and trying to create a notification history function. I’ve enabled the background modes successfully, so when the app is running in the background, the app can get the payload well via application:didReceiveRemoteNotification:fetchCompletionHandler even the banner/alert is not tapped. However, when force-quit / swipe up to kill the app, application:didReceiveRemoteNotification:fetchCompletionHandler is not called.
Is there any method to implement for getting the push notification payload when the app is killed without tapping the banner/alert? Thank you in advance!
You can't get a notification's payload if your app is killed.
In most cases, the system does not relaunch apps after they are force
quit by the user. One exception is location apps, which in iOS 8 and
later are relaunched after being force quit by the user. In other
cases, though, the user must launch the app explicitly or reboot the
device before the app can be launched automatically into the
background by the system. When password protection is enabled on the
device, the system does not launch an app in the background before the
user first unlocks the device. -
Understanding When Your App Gets Launched into the Background
Anyway, push notifications are not reliable.
It means that you can not be sure that they will ever be delivered.
If you want to keep a "notification history" list, do it server-side and fetch it in-app (in a totally not push related way).
Each time you send a push notification, keep it's content in database, like any object. Then when the user opens the history list, fetch the list like any other parse object.

Resources