AccessoryDataProvider
A protocol for an extension that receives iOS system notifications and curates their data for your accessory.
Declaration
protocol AccessoryDataProvider : AppExtension, Sendable where Self.Configuration : AccessoryDataProviderConfigurationMentioned in
Overview
Implement this protocol in an extension with an EXExtensionPointIdentifier value of com.apple.accessory-data-provider to receive notification data for eventual forwarding to an accessory that you develop. The extension runs in a sandboxed environment and communicates with the system through the extension’s configuration object (AccessoryDataProviderConfiguration).
Add the necessary target configuration
In your extension’s target properties, include the EXCapabilities key with the value AccessoryNotifications.NotificationsForwarding:
<plist>
<dict>
<key>EXAppExtensionAttributes</key>
<dict>
<key>EXExtensionPointIdentifier</key>
<string>com.apple.accessory-data-provider</string>
<key>EXCapabilities</key>
<array>
<string>AccessoryNotifications.NotificationsForwarding</string>
</array>
</dict>
</dict>
</plist>Implement the extension point
In your extension’s Swift code, implement the protocol and declare the capability with your NotificationsForwarding.AccessoryNotificationsHandler implementation:
struct DataProvider: AccessoryDataProvider {
var extensionPoint: AppExtensionPoint {
Identifier("com.apple.accessory-data-provider")
Implementing {
NotificationsForwarding {
MyNotificationsHandler()
}
}
}
}
class MyNotificationsHandler: AccessoryNotificationsHandler {
// Your extension's implementation.
}Share data between the app and the extension
Configure a shared app group so your companion app can provide information to the extension. The extension has read-only access to the shared container. Use the shared container to store:
Authentication tokens for your private servers
Accessory-specific preferences (max payload size, content filtering)
Device-specific configuration
// In the companion app, write to the shared container.
let sharedDefaults = UserDefaults(suiteName: "group.com.yourcompany.accessoryapp")
sharedDefaults?.set(authToken, forKey: "ServerAuthToken")
// In the extension, read from the shared container.
let sharedDefaults = UserDefaults(suiteName: "group.com.yourcompany.accessoryapp")
let authToken = sharedDefaults?.string(forKey: "ServerAuthToken")For more information, see Receiving iOS notifications on an accessory.