简体   繁体   中英

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?

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

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.

您的iOS应用程序在向用户显示之前无法修改传入的推送通知数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM