IOS Push Notification disable/enable on the basis of key - ios

Just wondering whether there is any way to disable/enable a push notification when it is received.
For e.g :- When i receive a push notification then i first check in my app whether in notification setting i have enabled or disabled the notification.
There can also be multiple notification settings like
To disable a friend request notification
To disable message notification
So while sending a notification is there any way to append notificationType like if its for friend request or messaging.
Then after checking the notification type and its corresponding setting in the app, showing or discarding the notification.

You can't achieve this just in client side itself. Because once notification arrives it is handled by iOS and displayed in notification centre (or any other type as per user setting). App will not get the notification info, unless it is running.
You can have this as settings in Client and sync it with server to have a check there before pushing the notifications.

Related

How to get push notification status using Swift?

In my app there is a setting to enable/disable push notification. Everything is fine with registering and my app is getting the notification.
Now I also unregister using UIApplication.shared.unregisterForRemoteNotifications() when I change in setting.
But when I try to fetch the status that app is already registered or not using UIApplication.shared.isRegisteredForRemoteNotifications then it always returns me true.
Any solution, how can I solve this?
I have implemented in this way in my app for push notification settings.
When user opt-out for push notification then I called an api(updateNotificaitonStatus with parameter "isEnabled = false") that disable the flag at server side for the push notification.
So whenever server has some data to send then...the server will check that is push notification enabled for the user?, if not, then just ignore to send the notification.
And if user changes his mind, and enabled the notification from app then agin an api call with the true flag(updateNotificaitonStatus with parameter "isEnabled = true").

APNS Modify Notification to be a Silent Notification

I have a weird feature I'm looking to add to iOS and am not sure if it's possible.
I want to send push notifications to all users through a third party and have the client decide whether or not to show it depending on some feature. I was reading that I can modify the notification before it reaches the app and was hoping that I could receive the notification, do some logic and, if the criteria is satisfied, modify the notification to be silent. But I'm not sure if this is possible.
Has anybody been able to do this?
As far as I know, it's not possible to hide a notification after it was sent.
You can modify the payload through a service extension but I'm pretty sure you cannot hide it from the user.
To decide on the client if a notification is visible or not - you'll have to send your notification as silent to begin with and then trigger a local notification.
The problems with that are:
Silent notifications are disabled if the user disabled Background Activity.
Silent notifications have a lower priority and might be throttled after a while.
The purpose of silent pushes is to inform the app of new content to perform a background fetch.
My recommendation is to put whatever logic you want on the server side before sending the notification.
For Android you can decide whether to show the notification or not.
For iOS, you can only modify the way the notification is presented but you cannot stop it from being shown. In order to modify the way the notification is presented to the user on iOS you need to add a Notification Extension Service.

Can I block receiving iOS Push Notifications during specified hours (night time) programmatically in Swift

my client wants to have an UISwitch control in Settings view in his app which is: 'Disable Notifications during night time'. He would like pushes that his API will be sending to mobile to be ignored if this option is turned on and it's a night time. Is this possible? I know that I can register and unregister for remote notifications, but this requires an App to be turned on. Is it possible to have it working like he wants?
The only way to do this is to have a configuration in the back-end. Notifications are sent from a server, and only handled in the app. There is no way, besides unregistering the phone from receiving notifications, to have the phone deny a notification in a certain time frame.
The user can set a time preference in the app, send it to the server, and have the server do a check so it only sends the notification to the user in the preferred time period.
Check out this 3rd party repo to send your push notifications and just write in your own check before pushing the notification.
https://github.com/nomad/houston
You can register or unregister for push notifications, i hope in your code switch you can make something like this:
let application = UIApplication.shared
//Didnt receive push
application.unregisterForRemoteNotifications()
//Receive push
application.registerForRemoteNotifications()
and if your client wants make this in Backend you can put a value on some database table with field receive:Bool, and the backend just take all the receive == true to send push notification on this devices

Suppress/Hide push notifications in iOS when the app is running

I receive push notifications on certain events from a notification server we have.
I do want these notification alerts to appear when the app is not active in the background/foreground
I don't want the notification alert to appear when the app is active in the background (foreground not a problem since the notification doesn't show anyway). I want to show my own local notification, only.
Is there any way to do this from code? Basically I want to hide the remote push notification and instead show a local notification when my app is active.
P.S - The notification server sending silent notifications is not an option - the server does not know when our app is running/not running. There is no communication between the app and this server.
You can notify your application first and then show a local notification with that. To perform this you can simply send content-available notification from server. This makes your app notified and then you can decide on showing local notification or not.

Objective C: Is it possible not to show iOS Push Notifications in specific conditions

Is it possible in iOS 7/8 not to show push notifications? In push userInfo I receive some data. Is it possible to check this data and show/not show this push notification? I need this when user have to logout from my application.
Sorry, You can not stop notification from being shown in notification panel. When your app is in background/terminate state. First Notification is shown in notification panel.
You can control show/hide notification in your application. When your app method didReceiveRemoteNotification is called.
You can ask your back-end developer to send some flag whether this notification should be displayed or not.
Yes,it is possible in server side.when you get notification at the same time ask server side to send save that in one web service from that you have to get and show the details to user.
In app is open that time you able get notification data in didReceiveRemoteNotification.

Resources