iOS any way to modify push notification alert message once received? - ios

My server yields push notifications with a payload including loc-key and loc-args, then when a message is received in the app it displays a notification based on the contents of Localizable.strings filling loc-key template with the content of loc-args.
I'd like to do some post processing for the content of the displayed notification, e.g. access user's address book locally and match a phone number to a contact name, and then display an updated alert while the app is running the background. Is there a way to do that?

You can use a silent push notification (content-available = 1) which will be delivered to application(_:didReceiveRemoteNotification:fetchCompletionHandler:) and then use the information in the push notification to create and display a local notification.
The only drawback with this approach is that your application delegate method won't be called if the user has terminated your app (swipe up from app switcher).

If app is in foreground you can catch and process the notification, but if the app is in background or the app is not running you have no access to the notification data.

Related

iOS push notification to remove delivered notification

I'm working on a app project that uses react-native and FCM Push Notification (rnfirebase 5.6.x).
I send a notification when the user receives some message and I need to remove that delivered notification if the user reads that message on another source (like our web app).
With the app open or in background, I can send another push with some userInfo to let me know what I need to remove.
Everything is working perfect... Except when the user kill the app. Then I have no control on the received notification...
I tried the use the tag prop on the notification data, but according with firebase, it is for Android only.
Any ideas on how to do that?

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.

Callback function for push notifications while app is killed (titanium iOS)

I cant find a clear answer about this in the Titanium documentation. Is it possible to directly respond to a push notification while the app is killed ?
I know that the callback is called when you open the app trough the push notification. but is there a way to respond when the app is opened manually ?
I tried to use remote-notification as UIBackgroundModes, but this only helps for paused apps.
My goal is to show the push notification in a in-app message center.
You should never rely on push notifications to deliver you payloads, they are too limited for that. If the user receives 5 push notifications and opens the app via the app icon, you will never receive any of the payloads. If he opens the app via one of those notifications you will only receive that payload.
You could use silentpush:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Background_Services-section-37539664_iOSBackgroundServices-SilentPush
But the app should always query a back-end to get the actual data. That's how WhatsApp does it as well, as you can see when you open it via a notification it will then still fetch the message(s) form the server.

Android can do it, what about iOS: can push-notification's payload be modified before it is shown to the user?

Can one change push-notification's payload (say, to remove any BBCode) before it is seen by the user? Android can do this inside GCM's public class GcmIntentService extends IntentService. Is this feasible on iOS?
There's two types of push, "normal" and background - the latter is only available with iOS7.
If your app is not running in the foreground and a normal push is sent to it then the OS displays it to the user and your app has no involvement in that process so the payload cannot be modified.
So in this situation the answer is no.
If your app is running in the foreground and a normal push is sent then the push is passed to the app, and the app can consume it and post a local notification with whatever payload it wants.
To a user a local notification and a push notification look the same, the user cannot distinguish between them.
So in this situation the answer is not literally yes but effectively yes.
If the app is running in the foreground or the background and a background push is sent to it then the app receives it and can consume it and post a local notification.
So in this situation the answer is also not literally yes but effectively yes.
If the app has been terminated by the user and a background push is sent to it then neither the app will receive it nor will it be displayed to the user.
If the app has been terminated by the user and a normal push is sent to it then it will be displayed to the user, with no involvement from the app.
If the app is in the foreground or background and a background push is sent to it while the user is on a phone call then the app will not receive the push nor will it be displayed to the user.
You don't have to change the payload before it is seen by the user. You can simply determine in advance (in the server side) which parts of the notification will be displayed, and which not.
The part of the notification payload that is displayed to the user is the alert field within the aps dictionary of the JSON payload. You can pass additional custom data outside the aps dictionary, that will be passed to your app (only if the app was running in the foreground when the notification arrived, or it wasn't running and the user tapped the notification to open the app) and won't be displayed to the user.
For example :
{
"aps" : {
"alert" : "shown to the user"
},
"custom_parameter" : "not shown to the user"
}
See here for more about the notification payload.

iOS - change a view's content on push notification received event

I'm coming from Android development background. In Android you send a push notification and then you handle the rest using a service (creating the actual system notification, modifying app's content, etc).
As far as I know, when sending iOS push notifications, it automatically creates a system notification for you in the notification center based on your message payload. After searching here and on google, I think I have to use application:didReceiveRemoteNotification event to add/remove a view's content. How can I access the push notification's content so I can put it in the app as well (I want to display the message in the app even if the user has dismissed the notification in the notification center)? There will be another message later on (usually the same day) to remove the message from the app.
I understand that the application:didReceiveRemoteNotification method won't be called if the app is closed, so I will have to use some other event (like didfinishlaunching) to get the message. But how do I access the push notification's message itself?
I want to display the message in the app even if the user has dismissed the notification in the notification center
This can't be done. iOS passes the notification data to your app only if the user opens the app from the notification center. If the user dismisses the notification and later launches the app, the only way for the app to get this data is to retrieve in from your server.
As for getting the notification data if the app is launched from the notification center, see this question.

Resources