Setting up the Notification Service Extension
Add a Notfication Service Extension target
In Xcode add a new Target to your application:
- In the menu
File > New > Target...
- Select
Notification Service Extension
- Give the name
NotificationService
This should create a new target with a bundle identifier like com.example.application.NotificationService
and a folder in your application called NotificationService
.
Identifiers
To share data between the main application and service extension targets, you need to add a common app group
to the main application identifier and new service extension identifier. Go the Apple Developer portal, in the Identifiers section select the App Groups dropdown to the right, then:
- Click
+
to add an App Group - Select
App Groups
from the list - Give the App Group a description and identifier, like
group.com.example.application
Update Identifiers
Now add the App Group to your existing main application release and debug Identifiers, in the Identifiers section select the App IDs dropdown to the right, then:
- Click the Identifier to edit
- Enable the
App Groups
app service - Click
Edit
and select the created app group
Create Service Extension Identifiers
Create new release and debug Identifiers for the new service extension.
- Click
+
to add an Identifier - Select
App IDs
from the list - Give the Identifier a description and identifier the same as the service extension, like
com.example.application.NotificationService
- Enable the
App Groups
app service - Save the Identifier, then edit again it to add the created app group as above
Provisioning Profiles
Once you've updated and created the application Identifiers, you need to create new Provisioning Profiles for the main application and service extension that include the app group service. Go the Apple Developer portal, in the Profiles section, then:
- Click
+
to add a Provisioning Profile - Select the Development or Distribution type depending if its for release or debug building
- Select the App ID
- Select the Certificate, then generate the Provisioning Profile making a note of the name
Configure Notification Service Extension
Back in Xcode you need to configure for each of your projects's targets, updating the Provisioning Profiles then adding capabilities for App Groups and Keychain Sharing. First for each target:
- Select the
Signing & Capabilities
tab - Update the Provisioning Profile to the newly created ones
Add an App Group Capability
Then add an App Group capability still in the Signing & Capabilities
tab for each target:
- Click
+ Capability
to add a capability - Select
App Groups
from the list - In the capability with the title
App Groups
, enable the created app group, likegroup.com.example.application
Add an Keychain Sharing Capability
Then add a Keychain Sharing capability still in the Signing & Capabilities
tab for each target:
- Click
+ Capability
to add a capability - Select
Keychain Sharing
from the list - In the capability with the title
Keychain Sharing
, add a name for the Keychain Group, likecom.example.SharedKeychain