---
title: "messageReceived(_:completion:)"
framework: accessorytransportextension
role: symbol
role_heading: Instance Method
path: "accessorytransportextension/accessorysecuritysession/eventhandler/messagereceived(_:completion:)"
---

# messageReceived(_:completion:)

Handles incoming key material from the system during key exchange.

## Declaration

```swift
func messageReceived(_ message: SecurityMessage, completion: @escaping @Sendable (AccessoryMessage.Result) -> Void)
```

## Parameters

- `message`: A security message containing cryptographic key material.
- `completion`: A closure to call when message processing completes.

## Mentioned in

Receiving iOS notifications on an accessory

## Discussion

Discussion The system calls this method with a SecurityMessage containing SecurityMessage.KeyType.encapsulatedKey after receiving your accessory’s public key. Forward the key material to your accessory via Bluetooth. Call the completion handler with AccessoryMessage.Result.success if transmission succeeds, or AccessoryMessage.Result.failure(_:) if an error occurs.
