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

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.

Related

receive push notification when a certain date expirespush notification

I have an app that has the Firebase Realtime Database as database.
In the app there are different products that expire after a certain time.
The database contains the expiry date and the exact time. How do I get the user to receive a push notification if the product is only available for 10 minutes, even if the app is completely closed?
Do I have to save the data on my device and send a local push notification from there?
Currently the user only receives a push notification when a new product is added.
A "local push notification" isn't really a thing. There are local notifications and push notifications. Push notifications are sent (pushed) from your server, through Apple's APNS (Apple Push Notification Server) and to your app's user.
You can schedule local notifications locally for some future time. There's really no difference to the user. It displays a message in the notification center which the user can tap to wake up your app, even if it wasn't running when the notification "goes off."
It sounds like you want to schedule a local notification.
If the trigger comes from your server then you could trigger a push notification. Those are also displayed to the user in the notification center whether your app is running or not.

Any way to know that a local iOS notification was displayed to the user if the user did not interact with it

I am trying to write a notification tracking system for my app. My understanding is that a scheduled local notification is guaranteed to get delivered but that my app won't get a notice that it was delivered unless the user interacts with that notification in some way. Am I missing something? Is there some event or notification sent to the app simply to indicate that the notification appeared?
No, I don't think you have any way of knowing about the "notification not taken."
A Jailbroken device would be a different matter.
There are silent push notifications, and I haven't looked at the new notifications API in iOS 10, so I guess it's possible Apple added a silent local notification for iOS 10...
Actually there are 2 scenarios:
App in background: When a local notification is delivered by the system, app is not notified, only if user interacts with notification view app is awakened.
App in foreground: App is notified when a local notification is delivered by calling didReceiveLocalNotification method.
Local notifications are guaranteed to be delivered only is user allows this (app will ask user to allow to receive local notifications)

IOS Push Notification disable/enable on the basis of key

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.

iOS Push Notifications without using a server

How do you go about sending users push notifications for automated actions in an app, such as sending them a notification when their lives have been refilled? This doesn't seem like an action that should need a server, but rather the app itself determines when to send out the notification.
What you need is not a push notification, but a local notification. See this question

Apple push notification-like service, only when running in foreground

I have an iOS app that needs to update its content while running in foreground automatically. My app does NOT need to update if in background.
There is a existing way to do so, which is APNS(Apple Push Notification Service).
Because I don't want users to see notification message while in background, using push notification without alert or message might be a solution.
However, if using APNS, iOS would ask users to confirm if they want to receive notifications by my app. I think that users may be confused when being asked by the OS since my app does not actually push notification to users.
The current method I use is keep pulling my API every 30 seconds to see if new content is available. This method would fail if there are too many users.
Is there any 3rd party push-notification-like service that provides notification while app runs in foreground only? (no need to get notification while in background)
You can use Silent notification for that, in this
In the WWDC 2013's "What's New with Multitasking" presentation, there is a section about Silent Push Notifications. if you send the APS payload with just the content-available set to 1, users will not be notified of the notification.
And the notification arrives in application:didReceiveRemoteNotification:fetchCompletionHandler:
Your payload is like
{
aps: {
content-available: 1,
sound: "default"
}
}
In case of push notification, it is necessary for user to accept push notification on application 1st run. You can set a silent push notification also and for this user will not get any alert of getting a notification during application run loop.
If you want to avoid push notification, then you can only set a NSTimer that you are doing already.
There can be a 3rd case, Application only sync with the server when it comes to foreground. And for this you can refer to my this post.

Resources