当我从 OneSignal 推送通知时,我想推送类似的东西
", you have received a message"
我想用类似的用户名替换应用程序中的 $name
notificationMessage = UserDefaults.standard.string(forKey: "username") + notificationMessage
是否可以覆盖通知?
最佳答案
如果您打算更改系统显示的警报,那么不,您不能更改这些。它们由操作系统管理。
仅适用于前景:
如果您有一些想要弹出的内部警报——当应用程序处于前台时,您可以随心所欲
例如你可以这样做:
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//1. extract notification data
let message = notification.request.content.body
let title = notification.request.content.title
// 2. use the message and title and change their values
// 3. use your new message and title and show your own custom alert.
// 4. I excluded the alert so you could show whatever you like yourself. But still I want to increase the badge and have sound when notification arrives...
completionHandler([.badge, .sound])
}
您不能更改请求
本身,因为它只是一个get
...
话虽如此,我不建议这样做。您的逻辑应该在您推送这些通知的服务器上处理。这应该是不必要的。
关于ios - 如何在收到时更改 iOS 通知消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47165457/