sparkFinder
sparkFinder

Reputation: 3404

Is it possible to modify incoming Push Notification Text on iOS

I have a usecase where a notification provider ends up sending me push notification text in a format that I'd like to change. Can I do so in the app's ObjectiveC/Swift code?

Upvotes: 9

Views: 5512

Answers (3)

Brandon Haugen
Brandon Haugen

Reputation: 959

Since iOS 10, it is possible to modify the text of push notifications (unless they are silent notifications) by creating a UNNotificationServiceExtension for your application.

The extension is created as a separate Target in Xcode and provides a NotificationService class with two functions, one that allows you to modify the content of the push notification (didReceive withContentHandler) and one that notifies your application if didReceive withContentHandler did not complete in time (serviceExtensionTimeWillExpire).

For this to work, the push notification that is sent to your application also needs to be modified to include the key/value pair mutable-content with a value of 1 so that iOS knows to invoke the UNNotificationServiceExtension for your application.

Apple's UNNotificationServiceExtension Documentation

Upvotes: 23

Sandeep Kumar
Sandeep Kumar

Reputation: 899

No you can't change the notification alert message(text), which user will see when app is not in foreground state. The use will see the same text what the notification payload contains.

Upvotes: 0

Mathew Spolin
Mathew Spolin

Reputation: 371

Your iOS app does not get a chance to modify the incoming push notification data before it is displayed to the user.

Upvotes: 1

Related Questions