<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HomeKit",
  "identifier" : "/documentation/HomeKit/HMHomeManagerDelegate/homeManager(_:didReceiveAddAccessoryRequest:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HomeKit"
    ],
    "preciseIdentifier" : "c:objc(pl)HMHomeManagerDelegate(im)homeManager:didReceiveAddAccessoryRequest:"
  },
  "title" : "homeManager(_:didReceiveAddAccessoryRequest:)"
}
-->

# homeManager(_:didReceiveAddAccessoryRequest:)

Tells the delegate to add an accessory to a home by using a setup payload.

```
optional func homeManager(_ manager: HMHomeManager, didReceiveAddAccessoryRequest request: HMAddAccessoryRequest)
```

## Parameters

`manager`

The home manager making the request.

`request`

A description of the accessory to add.

## Discussion

HomeKit calls this method when it needs help adding an accessory to a home, which typically occurs when the accessory requires explicit user authentication that HomeKit can’t negotiate. HomeKit asks the accessory manufacturer’s app, which it locates using information provided by the accessory, to complete the authentication.

If you manufacture an accessory like this, handle the [`homeManager(_:didReceiveAddAccessoryRequest:)`](/documentation/HomeKit/HMHomeManagerDelegate/homeManager(_:didReceiveAddAccessoryRequest:)) call in your app by creating an [`HMAccessoryOwnershipToken`](/documentation/HomeKit/HMAccessoryOwnershipToken) instance in a way that’s appropriate for your accessory, outside of HomeKit:

```swift
let data = negotiateTokenData(accessory: request.accessoryName)
guard let token = HMAccessoryOwnershipToken(data: data) else { return }
```

Use the resulting token to create an [`HMAccessorySetupPayload`](/documentation/HomeKit/HMAccessorySetupPayload) instance. If the request’s [`requiresSetupPayloadURL`](/documentation/HomeKit/HMAddAccessoryRequest/requiresSetupPayloadURL) flag is `true`, get the payload URL corresponding to the named accessory, and include that in the setup payload as well:

```swift
var payload: HMAccessorySetupPayload?
if request.requiresSetupPayloadURL {
    let payloadURL = getPayloadURL(accessory: request.accessoryName)
    payload = request.makePayload(url: payloadURL, ownershipToken: token)
} else {
    payload = request.makePayload(ownershipToken: token)
}
```

Complete the setup by calling the home’s [`addAndSetupAccessories(with:completionHandler:)`](/documentation/HomeKit/HMHome/addAndSetupAccessories(with:completionHandler:)) method with the payload:

```swift
if let payload = payload {
    request.home.addAndSetupAccessories(with: payload) { accessories, error in
        // Handle errors.
    }
}
```

---

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)