Implement the iOS and Android notification service extensions in your app.
NotificationCompat
options available.INotificationServiceExtension
and implement the onNotificationReceived
method.
The method onNotificationReceived
parameter is event
of type INotificationReceivedEvent .
AndroidManifest.xml
meta-data
within the AndroidManifest.xml
file in the application tag. Ignore any “unused” warnings.
OneSignalExtension.didReceiveNotificationExtensionRequest
. This is where we pass the bestAttemptContent
of the notification to the app before it is displayed to the user. Before this method is called, you can get the notification payload and (if desired) update it before it is displayed to the user.
In this example, we send a notification with the following data:
data
within the OneSignalNotificationServiceExtension via the custom
object using the a
parameter.
Notification Service Extension configuration in Xcode
Example shows the OneSignalNotificationServiceExtension target with the same Minimum Deployments as iOS 14.
NSExtension
key. Ensure you see:
Example viewing the Info tab and not the XML.
$(PRODUCT_MODULE_NAME).NotificationService
use NotificationService
.Embed App Extensions build phase settings
NotificationService.m
or NotificationService.swift
and replace the whole file contents with the below code. (The code is the same as our original setup code, just adding some additional logging.
Make sure to replace YOUR_BUNDLE_ID
with your actual Bundle ID.
OneSignalNotificationServiceExtension
.
Xcode active scheme selection
Xcode Devices and Simulators window
Device console access button
OneSignalNotificationServiceExtension
as the CATEGORYConsole debugging configuration
contents
property if sending from the Create message API). In this example, the payload is:
Console debug output example