Step by Step instructions to create a Notification Service Extension to send notifications with images in iOS
In this tutorial we assume that you have already made the certificates to publish your app in the App Store.
- Login to the Apple Developer Program
- Click in Certificates, Identifiers & Profiles > Identifiers
- Now click on + to add new identifier
- Select
App IDs
and continue - Select type
App
and continue - For the
Description
writeAppName Notification Service
or whatever you want - For the
Bundle ID
writeapp.package.name.NotificationService
an set inExplicit
- In
Capabilities
leave those selected by default, it is possible that if your main package usesAssociated Domains
you have to activate it here - Click now in continue to save identifier
- Go now to Profiles
- Now click on + to create new profile
- Select
App Store
and continue - Select you
app.package.name.NotificationService
and continue - From the list, select the certificate you are currently using to sign your app for the App Store and continue
- For the
Provisioning Profile Name
writeAppName Notification Service Profile
or whatever you want - Now click in Generate
- First, download the new Profile with Xcode > Preferences... > Accounts > Download Manual Profiles
- In you Xcode project, select File > New > Target and select
Notification Service Extension
- For the
Product Name
writeNotificationService
- Select in
Language
theSwift
- Replace the content of the created
NotificationService.swift
with the content of NotificationService.swift
- Change the
provisioningProfile
from youbuild.json
to an array with both profiles{"app.package.name":"00000000-0000-0000-0000-000000000000", "app.package.name.NotificationService":"00000000-0000-0000-0000-000000000000"}
Step 2, 3 (first line) and 5 will have to do them again when the profile expires. Step 3 and 4 will probably have to do it again if you eliminate and add the ios platform.
Now you can send notifications with images using the following payload.
{
"name": "my_notification",
"notification": {
"body": "Notification body",
"title": "Notification title"
},
"data": {
"notification_foreground": "true",
"notification_ios_image_jpg": "https://...",
"notification_ios_image_png": "https://...",
"notification_ios_image_gif": "https://...",
}
}