-
通过 Bluetooth Channel Sounding 查找你的配件
开始使用 Channel Sounding,为你的蓝牙配件带来距离和方向感知功能。深入探索全新的 Nearby Interaction 和 Core Bluetooth API,并详细了解你需要进行哪些配件端更改。在优化功耗的同时,确保顺畅灵敏的体验。
章节
- 0:01 - Introduction
- 0:50 - Overview
- 3:17 - Core Bluetooth API
- 4:34 - Nearby Interaction API
- 7:05 - Hardware tips
资源
相关视频
WWDC24
WWDC21
-
搜索此视频…
-
-
3:43 - Start a Core Bluetooth Channel Sounding session
import CoreBluetooth func isChannelSoundingSupported() -> BOOL { guard centralManager.state == .poweredOn else { return } if #available(iOS 27.0, *) { // Check current device supports Bluetooth Channel Sounding return CBCentralManager.supportsFeatures(.channelSounding) } } func startChannelSounding(_ peripheral: CBPeripheral) { guard peripheral.isConnected else { return } if #available(iOS 27.0, *) { // Step 1: Create a CBChannelSoundingSessionConfiguration let config = CBChannelSoundingSessionConfiguration(role: .initiator) // Step 2: Start the channel sounding session peripheral.startChannelSoundingSession(config) } } -
4:09 - Receive distance results and cancel a session
import CoreBluetooth // Receive distance results func peripheral(_ peripheral: CBPeripheral, didReceive results: CBChannelSoundingProcedureResults?, error: Error?) { guard let results = results else { return } let distance = results.distance // Do something with distance } // Cancel a Channel Sounding session func cancelChannelSounding(_ peripheral: CBPeripheral) { guard peripheral.isConnected else { return } if #available(iOS 27.0, *) { // Cancel the channel sounding session peripheral.cancelChannelSoundingSession(config) } } func peripheral(_ peripheral: CBPeripheral, didCompleteChannelSoundingSession error: Error?) { // Session is complete } -
4:41 - Start a Nearby Interaction Channel Sounding session
import CoreBluetooth import NearbyInteraction // Configure a Nearby Interaction Channel Sounding session func startChannelSoundingThroughNearbyInteraction(_ peripheral: CBPeripheral) { if #available(iOS 27.0, *) { // Step 1: Check current device supports Bluetooth Channel Sounding guard NISession.deviceCapabilities.supportsBluetoothChannelSounding else { return } // Step 2: Create an NINearbyAccessoryConfiguration let config = NINearbyAccessoryConfiguration( bluetoothChannelSoundingIdentifier: peripheral.identifier, previousChannelSoundingIdentifier: nil) // Step 3: Enable camera assistance for direction support if NISession.deviceCapabilities.supportsCameraAssistance { config.isCameraAssistanceEnabled = true } } } -
5:19 - Run a Nearby Interaction Channel Sounding session
import CoreBluetooth import NearbyInteraction // Run a Nearby Interaction Channel Sounding session func runChannelSoundingThroughNearbyInteraction(_ config: NINearbyAccessoryConfiguration) { // Create an NISession let session = NISession() session.delegate = self // Run the NISession with the accessory configuration session.run(config) } // Improve Nearby Interaction direction outputs func updateAccessoryMotionState(_ isMoving: Bool) { NIMotionActivityState motionState = isMoving ? .moving : .stationary // Tell NISession about.the accessory's motion state session.updateMotionState(motionState, forObjectWithToken: object.discoveryToken) } // Receive NISession updates func session(_ session: NISession, didUpdate nearbyObjects: [NINearbyObjects]) { guard let object = nearbyObjects.first else { return } if let distance = object.distance { // Do something with distance } if let direction = object.horizontalAngle { // Do something with horizontal angle } }
-
-
- 0:01 - Introduction
Discover the three aspects of Bluetooth Channel Sounding that will be discussed in this video.
- 0:50 - Overview
Find inspiration for using Bluetooth Channel Sounding.
- 3:17 - Core Bluetooth API
Learn how to get distance with the Core Bluetooth API.
- 4:34 - Nearby Interaction API
Get distance and direction with the Nearby Interaction API.
- 7:05 - Hardware tips
Understand the hardware requirements for Bluetooth Channel Sounding.