Contents

updateMotionState(_:forObjectWithToken:)

Notifies the session of an accessory’s motion state change.

Declaration

func updateMotionState(_ motionState: NIMotionActivityState, forObjectWithToken token: NIDiscoveryToken)

Parameters

  • motionState:

    The current motion state of the accessory.

  • token:

    The discovery token that identifies the nearby accessory.

Discussion

Ranging accuracy improves when the framework knows whether the accessory is moving. Track your accessory’s motion using a method you choose and then describe the motion with the appropriate NIMotionActivityState. Call this method, providing the motion state, when the accessory’s motion state changes:

func handleMotionStateUpdate(_ state: NIMotionActivityState, session: NISession) {
    guard let config = session.configuration as? NINearbyAccessoryConfiguration else {
        return
    }
    session.updateMotionState(state, forObjectWithToken: config.accessoryDiscoveryToken)
}

This method works with NINearbyAccessoryConfiguration sessions, and applies to Ultra Wideband and Bluetooth Channel Sounding sessions.

See Also

Providing accessory state information