<!--
{
  "availability" : [
    "iOS: 26.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AccessoryNotifications",
  "identifier" : "/documentation/AccessoryNotifications/NotificationsForwarding/AccessoryNotificationsHandler/messageHandler(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accessory Notifications"
    ],
    "preciseIdentifier" : "s:22AccessoryNotifications0B10ForwardingC0aB7HandlerP07messageD0yy0A18TransportExtension0F7MessageVF"
  },
  "title" : "messageHandler(_:)"
}
-->

# messageHandler(_:)

Handles decrypted messages received from the paired accessory.

```
func messageHandler(_ message: TransportMessage)
```

## Parameters

`message`

The decrypted message payload from the accessory.

## Discussion

The system calls this method when your accessory sends data to the data provider extension. For Bluetooth transport, the accessory sends data through your transport extension using <doc://com.apple.documentation/documentation/AccessoryTransportExtension/AccessoryTransportSession/sendMessageToDataProvider(_:)>. For internet transport, the accessory routes data to the device through APNs using <doc://com.apple.documentation/documentation/AccessoryTransportExtension/AccessoryTransportSession/pushToken>. In either case, the system delivers decrypted messages to this method regardless of the transport type.

## Process notification responses

Parse the message to determine the response type (notification dismissal, action selection, or text input). Create a [`NotificationResponse`](/documentation/AccessoryNotifications/NotificationResponse) instance and send it to the system using [`sendResponse(_:)`](/documentation/AccessoryNotifications/NotificationsForwarding/AccessoryNotificationsSession/sendResponse(_:)):

```swift
func messageHandler(_ message: AccessoryMessage) {
    for payload in message.payloads {
        let parsedResponse = parseResponse(payload.data)
        
        let response = NotificationResponse(
            sourceIdentifier: parsedResponse.sourceID,
            notificationIdentifier: parsedResponse.notificationID,
            actionIdentifier: parsedResponse.actionID,
            userText: parsedResponse.userText
        )
        
        Task {
            try await session?.sendResponse(response)
        }
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)