<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "watchOS: 7.3.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "NearbyInteraction",
  "identifier" : "/documentation/NearbyInteraction/NISessionDelegate/session(_:didUpdate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Nearby Interaction"
    ],
    "preciseIdentifier" : "c:objc(pl)NISessionDelegate(im)session:didUpdateNearbyObjects:"
  },
  "title" : "session(_:didUpdate:)"
}
-->

# session(_:didUpdate:)

Notifies you when the session updates nearby objects.

```
optional func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject])
```

## Parameters

`session`

The session that updated.

`nearbyObjects`

The array of nearby objects that the session updated.

## Discussion

Implement this callback to receive new nearby object updates for the argument session.

In Swift, if a peer is out of range or line of sight, the delegate reads the [`distance`](/documentation/NearbyInteraction/NINearbyObject/distance-676dm) and [`direction`](/documentation/NearbyInteraction/NINearbyObject/direction-4qh5w) as `nil`. An app can monitor this state and guide a person into range as necessary. For more information, see [Initiating and maintaining a session](/documentation/NearbyInteraction/initiating-and-maintaining-a-session).

In Objective-C, if a peer is out of range or line of sight, the delegate reads the [`distance`](/documentation/NearbyInteraction/NINearbyObject/distance-676dm) as [`NINearbyObjectDistanceNotAvailable`](/documentation/NearbyInteraction/NINearbyObjectDistanceNotAvailable), and [`direction`](/documentation/NearbyInteraction/NINearbyObject/direction-4qh5w) as [`NINearbyObjectDirectionNotAvailable`](/documentation/NearbyInteraction/NINearbyObjectDirectionNotAvailable).

An app can monitor this state and guide the user into range as necessary. For more information, see [Initiating and maintaining a session](/documentation/NearbyInteraction/initiating-and-maintaining-a-session).

### Provide feedback based on proximity

Apps can react to positional information in an interaction session to create spatial awareness. For example, an app can play audio, invoke haptics, or display visual feedback when a peer is nearby. The following code calls two functions: it calls `enableFunctionalityA` when the device achieves a 1.5-meter proximity to the peer device, and `enableFunctionalityB` when the device achieves a 3-meter proximity to the peer device.

```swift
func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObject]) {
    // Ensure there's a current peer token.
    guard let peerToken = peerDiscoveryToken else {
        fatalError("don't have peer token")
    }

    // Find the right peer from session update.
    guard let peerObj = nearbyObjects.first (where: { $0.discoveryToken == peerToken }) else {
        return
    }

    // Retrieve the peer's distance, in meters.
    if let distance = peerObj.distance {
        // Compute peer object's distance.
    }
                
    // Retrieve the peer's horizontal angle, in radians.
    if let horizontalAngle = peerObj.horizontalAngle {
        // Compute peer object's angle.
    }

    // Retrieve the peer's direction, in `simd_float3`.
    if let direction = peerObj.direction {
        // Compute peer object's direction.
    }
}
```

---

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)