It's Possible to Change Push Notification Message Before Display on Device from iOS Side

It's possible to change push notification message before display on device from iOS side?

There are various possibilities for preprocessing and modify the payload of a notification on iOS.

Before iOS 10

You could be sending Silent Notifications, what will not be not shown to the user. Will wake our application when it is terminated or in background, and you will be able to do preprocessing on the notification content. See more info here, how to set it up. However, this notification type is not 100% reliable, and should not be abused, e.g. used for all notifications to be delivered, because Apple could stop the notifications to be sent after a number of messages.

The other option is, if your application supports VoIP. This way your app will pretty much always listen to push notifications, and you will be always available to preprocess the notifications, before you would be displaying them. However, if your app does not have real VoIP capabilities, e.g. phone calls, your app will be rejected by Apple on the review. Here is a great tutorial, how to set it up.

From iOS 10

With the introduction of iOS 10, we are finally able to do preprocessing on our notifications, even, when the app is in background or terminated. No VoIP capabilities or special type of notifications needed to be sent. Here is a great tutorial, how to set it up.

Apple Push Notification : Can we remove some text from notification message before it has to be displayed to user on iphone

The payload data which we send to APNS server is going to display on device. If you have to remove some text then it must have to remove before sending to APNS server. You can not manage notification text message.

What is Silent Push Notification? When does the device receive it?

They can be used to inform the application of new content without having the user informed. Instead of displaying a notification alert, the application will be awakened in background (iOS does not automatically launch your app if the user has force-quit it) and application:didReceiveRemoteNotification:fetchCompletionHandler: will be called. You then have the opportunity to process any information transparently for the user :

  • Download some content
  • Synchronize some elements,
  • Inform the user directly within the application when he opens it back

Note that your time is limited to 30s.

To configure silent notifications

To support silent remote notifications, add the remote-notification value to the UIBackgroundModes array in your Info.plist file. To learn more about this array, see UIBackgroundModes.

<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
</array>

Configuring a Silent Notification

The aps dictionary can also contain the content-available property. The content- available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don’t follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user

How can I intercept an iOS Push Notification before it's displayed on the lock screen notification center?

You can send whatever you want trough notifications, there some value that you iOS device will take as mandatory, if you send the following message you can show some message and send additional data with the notification, imagine this base notification:

{
aps: {
alert: "Hi there"
}
}

This notification will show the alert message on the lock screen and the notification bar on you device, but can also send this:

{
aps: {
alert: "Hi there",
content-available: 1, // Add this if you want background processing
sound: "" // If you don't want to show the notification on the notification area nor the lock screen.
}
data: {
effectiveTime: ...,
expirationTime: ...,
message: ...,
...
}
}

This will show exactly the same notification on you device than the first one, but in this case you can do anything you want with the data using didReceiveRemoteNotification: method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"My data sent trough GCM: %@", userInfo[@"data"]);
}

The only keys you can use to your data are the listed in 3-1 and 3-2 on the official push notifications docs

If you want to manage background processing, according to the docs you should use (as you said) the application:didReceiveRemoteNotification:fetchCompletionHandler: but everything else remain the same:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {

switch (application.applicationState) {
case UIApplicationStateInactive:
// Do whatever you want if the app is inactive
handler(UIBackgroundFetchResultNewData);
break;

case UIApplicationStateBackground:
// Do whatever you want if the app is in background
handler(UIBackgroundFetchResultNewData);
break;

case default:
// Do whatever you want if the app is active
handler(UIBackgroundFetchResultNewData);
break;
}
}

How to change notification message in ios by objective c code?

Whatever is sent in the payload of the push notification is displayed in the banner shown to the user. If you want to customize this message, you'll have to change what you are sending to the APNs service. See the push notification programming guide for details: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1



Related Topics



Leave a reply



Submit