【问题标题】:How to change iOS notification message upon receiving?收到后如何更改iOS通知消息?
【发布时间】:2017-11-07 18:53:30
【问题描述】:

当我从 OneSignal 推送通知时,我想推送类似的东西

", you have received a message"

我想将 app 中的 $name 替换为类似的用户名

notificationMessage = UserDefaults.standard.string(forKey: "username") + notificationMessage

是否可以覆盖通知?

【问题讨论】:

    标签: ios swift notifications apple-push-notifications onesignal


    【解决方案1】:

    如果您要更改系统显示的警报,那么您不能更改这些。它们由操作系统管理。

    仅用于前台:

    如果您想要弹出一些内部警报 - 当应用程序处于前台时,您可以随意操作

    例如,您可以执行以下操作:

    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])
    }
    

    你不能改变request本身,因为它只是get...

    话虽如此,我不建议这样做。您的逻辑应该在您推送这些通知的服务器上处理。这应该是不必要的。

    【讨论】:

    • 如何在后台自定义警报通知文本?还是不可行?
    • @MamdouhElNakeeb 这由操作系统处理。不可行。最好还是让服务器完全处理该逻辑。
    • @MamdouhElNakeeb Akkh al-arab,天哪!拉yumkin!
    • @MamdouhElNakeeb 操作系统即将显示它的那一刻,您无法更改,操作系统不会告诉您“我要显示这个,想要进行更改?”但是,您可以更新内容已传递 通知(远程或本地)或稍后将传递的本地通知。见here。这可能是你需要的
    • 我需要根据收到的远程通知生成不同的本地通知。你有我的问题吗?
    猜你喜欢
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    相关资源
    最近更新 更多