AccessoryTransportAppExtension
A protocol for an extension that transmits data to an accessory you develop.
Declaration
protocol AccessoryTransportAppExtension : AppExtensionMentioned in
Overview
Implement this protocol in an extension with an EXExtensionPointIdentifier value of com.apple.accessory-transport-extension to relay data to your accessory. The extension supports sharing Wi-Fi networks and forwarding iOS system notifications.
Wi-Fi network sharing
Use this extension with Wi-Fi Infrastructure to share a Wi-Fi network with your accessory. The system calls your extension’s accept(sessionRequest:) method when it needs to establish a transport session for Wi-Fi sharing.
In your extension’s target properties, specify the extension point identifier:
<plist>
<dict>
<key>EXAppExtensionAttributes</key>
<dict>
<key>EXExtensionPointIdentifier</key>
<string>com.apple.accessory-transport-extension</string>
</dict>
</dict>
</plist>In your extension’s Swift code, implement the protocol and provide an event handler:
@main
struct TransportExtension: AccessoryTransportAppExtension {
func accept(sessionRequest: AccessoryTransportSession.Request) -> AccessoryTransportSession.Request.Decision {
return sessionRequest.accept {
MyTransportEventHandler(session: sessionRequest.session)
}
}
}
class MyTransportEventHandler: AccessoryTransportSession.EventHandler {
func invalidationHandler(error: AccessoryTransportSession.Error?) {
// Clean up when the session ends.
}
}After accepting a session, your extension connects directly to the accessory using ASAccessorySession and delivers Wi-Fi network data using WINetworkSharingProvider.
Notification forwarding
For notification forwarding, set up your extension the same way as for Wi-Fi network sharing. The system invokes your extension to relay encrypted notification data from your app’s AccessoryDataProvider extension to your accessory.
Implement dataEventHandler(event:) in your event handler to receive and transmit data:
class MyTransportEventHandler: AccessoryTransportSession.EventHandler {
func dataEventHandler(event: AccessoryTransportSession.DataEvent) {
switch event {
case .ciphertext(let data, let featureID):
// Transmit encrypted notification data to accessory over Bluetooth.
sendToAccessory(data)
case .plaintext(let data, let featureID):
// Transmit plaintext data to accessory.
sendToAccessory(data)
}
}
func invalidationHandler(error: AccessoryTransportSession.Error?) {
// Clean up when the session ends.
}
}The system encrypts data using keys through your app’s AccessoryTransportSecurity (ATS) extension and then delivers the encrypted data as ciphertext to your handler. Your extension transmits the encrypted data to the accessory, which decrypts the data using shared encryption keys.