Thiha Aung
Thiha Aung

Reputation: 5106

How to customize remote notification title and body from client device?

I want to customize the remote notification on my client device before it showed on user interface.Especially,I want to edit title and body to show at LockScreen,Banners and NotificationCenter every time notification arrive and them display like banner.I don't want to set server notification title and body.I only want to set customize on client device before it showed.

Is there any way?

Any Guide?

Upvotes: 3

Views: 2189

Answers (1)

Hitendra Solanki
Hitendra Solanki

Reputation: 4941

{
    "aps" : {
        "alert" : "",
        "content-available" : 1
    },
    "action" : "update",
    "extraData" : {
        "updateType" : 2,
        "updateMessage" : "New version available 1.1.2"
    }
}

The aps dictionary have to have key content-available with value 1, so whenever your device receives remote-notification with this key and value, it will consider as silent-notification.

The value for key alert must be blank string "". otherwise iOS system will show that notification.

Whenever the iOS operating system receives a silent-notification, it will trigger the application:didReceiveRemoteNotification:fetchCompletionHandler: method of your AppDelegate class. In this method you can get the notification's payload through the userInfo parameter.

In above payload, action and and extraData are my custom data. Based on that you can process your received notification. In the above I am changing the text of the notification based on the string updateMessage, by appending another string. After changing the string you can schedule a local-notification: this way you can change the text of the received remote-notification.

You have to enable background mode for remote notifications.

enter image description here

Upvotes: 4

Related Questions