Hi All,Here I am going to tell that how we can change the content of remote notification in iOS.

Generally we found in iOS application , the notification will popup with there default title comes under the section of alert . We can change the the data of notification with the help of Notification Service Extension.

Follow the steps describe below:-

In Xcode select file->new->target->iOS->Notification Service Extension(as shown in image Below). 

Click on Next button.We found two file :-
1:- ServiceExtension.swift
2:- info.plist

We don’t need to change the info.plist file . It automatically import the two attributes in that file i.e. NSExtensionPointIdentifier and NSExtensionPrincipalClass.We just on push notification in the capabilities section into the extension as well as your project.

In NotificationService.swift there will have two Method i.e as follows.:-

You can modify the content of notification as per the user requirement in did Receive Function. With the help of UNNotification Service Extension we can change the static or animated (GIF) image , or even a video to push notifications as well as modify the notification content prior to show it to the user. But what is more important for us is that with the Notification Service Extensions we can run arbitrary code in background even if your main application is killed by the user. This feature gives us an opportunity to improve message handling and delivery reporting. 


When a remote notification for your app is received, the system loads your extension and calls its didReceive(_:withContentHandler:) method only when both of the following conditions are met:

  • The remote notification is configured to display an alert.
  • The remote notification’s aps dictionary includes the mutable-content key with the value set to 1.

    “The didReceive(_:withContentHandler:) method performs the main work of your extension. You use that method to make any changes to the notification’s content. That method has a limited amount of time to perform its task and execute the provided completion block. If your method does not finish in time, the system calls the serviceExtensionTimeWillExpire() method to give you one last chance to submit your changes. If you don’t update the notification content before time expires, the system displays the original content.”

Thank & Regards

Rohit Gupta