Core Bluetooth

RSS for tag

Communicate with Bluetooth 4.0 low energy devices using Core Bluetooth.

Posts under Core Bluetooth tag

186 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Bluetooth peripheral factory reset
Hi, I'm developing a bluetooth peripheral. During factory reset I generate a new IRK and drop any bond information it has. When I then try to bond again with the device iOS returns bonding failed with 0x08 (unspecified reason). I assume that iOS somehow still thinks my reset device is the same as the device it has already bonded with. What information about the device is it using to draw this conclusion? Bonding works if I remove the "pre-reset" peripheral from the iOS list of bluetooth devices. Regards
1
0
178
Mar ’25
Playing audio live from Bluetooth headset on iPhone speaker
Hi guys, I am having issue in live-streaming audio from Bluetooth headset and playing it live on the iPhone speaker. I am able to redirect audio back to the headset but this is not what I want. The issue happens when I am trying to override output - the iPhone switches to speaker but also switches a microphone. This is example of the code: import AVFoundation class AudioRecorder { let player: AVAudioPlayerNode let engine:AVAudioEngine let audioSession:AVAudioSession let audioSessionOutput:AVAudioSession init() { self.player = AVAudioPlayerNode() self.engine = AVAudioEngine() self.audioSession = AVAudioSession.sharedInstance() self.audioSessionOutput = AVAudioSession() do { try self.audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: [.defaultToSpeaker]) try self.audioSessionOutput.setCategory(AVAudioSession.Category.playAndRecord, options: [.allowBluetooth]) // enables Bluetooth HFP profile try self.audioSession.setMode(AVAudioSession.Mode.default) try self.audioSession.setActive(true) // try self.audioSession.overrideOutputAudioPort(.speaker) // doens't work } catch { print(error) } let input = self.engine.inputNode self.engine.attach(self.player) let bus = 0 let inputFormat = input.inputFormat(forBus: bus) self.engine.connect(self.player, to: engine.mainMixerNode, format: inputFormat) input.installTap(onBus: bus, bufferSize: 512, format: inputFormat) { (buffer, time) -> Void in self.player.scheduleBuffer(buffer) print(buffer) } } public func start() { try! self.engine.start() self.player.play() } public func stop() { self.player.stop() self.engine.stop() } } I am not sure if this is a bug or not. Can somebody point me into the right direction? I there a way to design a custom audio routing? I would also appreciate some good documentation besides AVFoundation docs.
0
0
265
Mar ’25
CoreBluetooth Scan not working when OS upgraded to 18.3.1
Hi, I currently have an app that connect to an arduno via CoreBluetooth. However, the app no longer discovers the arduino when the operating system was upgraded to iOS 18.3.1, however on iOS version 17.6.1 the ardiuno was discoverable I was able to test this theory on two different phones each with different iOS versions. Why are my peripherals no longer being discovered with this update? and what is the solution?
0
0
188
Mar ’25
CoreBluetooth Scan not working when OS upgraded to 18.3.1
Hi, I currently have an app that connect to an arduno via CoreBluetooth. However, the app no longer discovers the arduino when the operating system was upgraded to iOS 18.3.1, however on iOS version 17.6.1 the ardiuno was discoverable I was able to test this theory on two different phones each with different iOS versions. I see that it is failing to find the peripheral at the scan however the logs indicate that the central state is powered on. Why are my peripherals no longer being discovered with this update? and what is the solution?
3
0
257
Mar ’25
Technical Inquiry about CoreBluetooth Scanning & NEHotspotConfigurationManager Workflow
I am writing to seek clarification on two technical issues related to iOS frameworks (CoreBluetooth and NetworkExtension). These observations are critical for optimizing our app's performance, and I would appreciate any official guidance or documentation references. CoreBluetooth Scanning Frequency and Cycle Issue: We noticed inconsistent BLE device discovery times (ranging from 0.5s to 1.5s) despite the peripheral advertising at 2Hz (500ms interval). Questions: Does iOS regulate the BLE scan interval or duty cycle internally? If yes, what factors affect this behavior (e.g., foreground/background state, connected devices)? Are there recommended practices to reduce discovery latency for peripherals with fixed advertising intervals? Is there a way to configure scan parameters (e.g., scan window/interval) programmatically, similar to Android's BluetoothLeScanner? Test Context: Device: iPhone 13 mini (iOS 17.6.1) Code: CBCentralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true]) NEHotspotConfigurationManager Workflow and Latency Issue: Using NEHotspotConfigurationManager.shared.apply(_:) to connect to Wi-Fi occasionally takes up to 8 seconds to complete. Questions: What is the internal workflow of the apply method? Does it include user permission checks, SSID scanning, authentication, or IP assignment steps? Are there known scenarios where this method would block for extended periods (e.g., waiting for user interaction, network timeouts)? Is the latency related to system-level retries or radio coexistence with other wireless activities (e.g., Bluetooth)? Test Context: Configuration: NEHotspotConfiguration(ssid: "TestSSID") Behavior: Delay occurs even when the Wi-Fi network is in range and credentials are correct.
1
0
157
Mar ’25
Technical Inquiry about CoreBluetooth Scanning
Issue: We noticed inconsistent BLE device discovery times (ranging from 0.5s to 1.5s) despite the peripheral advertising at 2Hz (500ms interval). Questions: Does iOS regulate the BLE scan interval or duty cycle internally? If yes, what factors affect this behavior (e.g., foreground/background state, connected devices)? Are there recommended practices to reduce discovery latency for peripherals with fixed advertising intervals? Is there a way to configure scan parameters (e.g., scan window/interval) programmatically, similar to Android's BluetoothLeScanner? Test Context: Device: iPhone 13 mini (iOS 17.6.1) Code: CBCentralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
0
0
103
Mar ’25
CoreBluetooth and Swift strict concurrency checking
As of iOS 18.3 SDK, Core Bluetooth is still mostly an Objective-C framework: key objects like CBPeripheral inherit from NSObjectProtocol and does not conform to Sendable. CBCentralManager has a convenience initializer that allows the caller to provide a dispatch_queue for delegate callbacks. I want my Swift package that implements Core Bluetooth to conform to Swift 6 strict concurrency checking. It is unsafe to dispatch the delegate events onto my own actor, as the passed in objects are presumably not thread-safe. What is the recommended concurrency safe way to implement Core Bluetooth in Swift 6 with strict concurrency checking enabled?
0
0
94
Mar ’25
BLE scan response persists after advertisements stop
I'm experimenting with advertising packets using Core Bluetooth on iOS as a Peripheral. I'm using an iPhone 13 mini as my test device. I've found that if I set a 128-bit CBAdvertisementDataServiceUUIDsKey, and a 8 byte CBAdvertisementDataLocalNameKey and call CBPeripheralManager::startAdvertising() I can see both data elements in a advertising report of type "legacy advertising indication", when scanning from another device. But if I add one or more extra bytes, the "Local Name" field is no longer in the same report. Instead, it is moved to the scan response. This is good, but a funky thing happens when I stop advertising. The legacy advertising indication becomes empty, however, the scan response, with the same data, continues to appear in every scan by the other device! I've tried calling stopAdvertising(), ending the debug session, closing the app, and force quitting (slide up from app choser), The only thing that seems to stop them is turning off Bluetooth in Settings. Is this normal behaviour?
2
0
58
Mar ’25
Bluetooth
你好,有个问题想请教一下: 我们的app是一款与CGM实时血糖相关的app,app支持在后台通过蓝牙跟CGM血糖设备保持连接。 现在遇到一个问题: 首先,app在后台运行期间,蓝牙是开启状态的,跟CGM设备也是连接的状态。 某个时刻,监听到蓝牙的状态突然从 poweredOn 变为了 resetting ,然后蓝牙又恢复了,状态变为了 poweredOn 这时候,问题出现了:之前连接的那个CGM血糖设备一直无法扫描到了!! 我想问一下: 什么情况下,蓝牙状态会变为resetting 蓝牙状态恢复为poweredOn后,之前连接的那个CGM血糖设备一直无法扫描到了,为什么?我要怎么做才能恢复,重新扫描到之前连接的这个设备?
1
0
59
Mar ’25
Does peripheralManager.updateValue Actually Send Data to the Central?
https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/updatevalue(_:for:onsubscribedcentrals:) I want to record the timestamp when an iOS peripheral sends data to a central device. Here’s what I did: let startDate = Date() if peripheralManager.updateValue(packet, for: characteristic, onSubscribedCentrals: nil) { let sentTime = Date().timeIntervalSince(startDate) } However, the recorded time is nearly 0.1 ms. If I send 244 bytes per update, this suggests a throughput of 2.44 MB/s, which seems too high. Did I make a mistake, or is updateValue() not actually sending the data at that moment?
1
0
62
Mar ’25
Inconsistent BLE Extended Advertising Scanning on iOS
I'm developing an iOS 18 app using Core Bluetooth on an iPhone 16 Pro to scan for BLE Extended Advertising packets. However, scanning behavior is inconsistent. Sometimes, the app detects extended advertising packets correctly, but other times, it fails to find them even when the advertiser is active. I tested using nRF Connect on both my iPhone 16 Pro and another Android device that I'm also developing an app for. The Android device consistently detects the extended advertising packets, but my iPhone 16 Pro has inconsistent results. Legacy advertising packets are scanned without any issues. The same peripheral is consistently detected on Android and other BLE scanners. I've tested with different scan settings, restarted Bluetooth, and rebooted the device, but the issue persists. Does iOS 18 have any known limitations with BLE Extended Advertising? Any workarounds to improve scanning reliability?
0
0
68
Mar ’25
Alternative to MAC Address for Uniqueness in iOS Bluetooth Connection
I am developing a React Native app for a health monitoring device that connects via Bluetooth and streams live data on iOS. To ensure the uniqueness of the device, I initially planned to use the MAC address. However, I discovered that iOS does not provide access to the original MAC address due to privacy restrictions. Is there an alternative approach to uniquely identifying a Bluetooth device in iOS? I need a reliable way to distinguish devices while maintaining secure and stable connections. Any insights or best practices on handling this in iOS would be greatly appreciated. Looking forward to hearing your suggestions! If anyone has experience with handling Bluetooth device uniqueness on iOS, please share your insights. Thank you!
1
0
49
Apr ’25
How to Maintain Background Connection with BLE-Triggered WebSocket Companion Hub for Real-Time Alerts on iOS
I’m building a companion app that connects to a custom hardware hub (IoT device) used for home safety monitoring. The hub is installed in homes and is responsible for triggering critical alerts like fire alarms, motion detection, door sensor activity, and baby monitor events. Current Architecture: The hub initially connects to the app via Bluetooth (BLE) for provisioning (to get Wi-Fi credentials). Once provisioned, the hub switches to Wi-Fi and communicates with the app via a WebSocket connection to stream real-time event updates. What I’m Trying to Achieve: My goal is to maintain background communication with the hub even when the app is not actively in use, in order to: Receive real-time updates from the hub while the device is locked or the app is in background. Trigger local notifications immediately when critical sensor events (e.g., fire, motion) occur. Ensure persistence across backgrounding, app swipes (force close), and device reboots, if possible. What I'm Observing: On iOS, WebSocket connection is suspended or dropped shortly after the app goes to the background or is locked. Even though the I've scheduled periodic fetches, notifications are delayed until the app is reopened, at which point all missed WebSocket messages arrive at once. If the app is force-closed or after reboot, no reconnection or notification happens at all. Key Questions I Have: Since the hub is initially provisioned via BLE, and could potentially send BLE flags or triggers for key events, can I use bluetooth-central mode to keep the app active or wake it up on BLE activity? Once the hub switches to Wi-Fi and uses WebSocket, is it possible to combine BLE triggers to wake the app and then reconnect to the WebSocket to fetch the full event payload? Is there a legitimate and App Store-compliant way to maintain a connection or background task with: BLE accessory triggers followed by Real-time data processing via Wi-Fi/WebSocket? Would this use case qualify as a "companion device" scenario under iOS background execution policies? What is the best practice for handling this kind of hybrid BLE + WebSocket alerting flow to ensure timely user notifications, even in background/locked/force-closed states? Any advice, documentation links, implementation patterns, or examples from similar companion device apps would be greatly appreciated. Thanks in advance!
1
0
100
Apr ’25
Working with Input/Output stream with Swift 6 and concurrency framework
Hello, I am developing an application which is communicating with external device using BLE and L2CAP. I wonder what are the best practices of using Input & Output streams that are established with L2CAP connection when working with Swift 6 concurrency model. I've been trying to find some examples and hints for some time now but unfortunately there isn't much available. One useful thread I've found is: https://developer.apple.com/forums/thread/756281 but it does not offer much insight into using eg. actor model with streams. I wonder if something has changed in this regards? Also, are there any plans to migrate eg. CoreBluetooth stack to new swift 6 concurrency ?
2
0
91
Apr ’25
can bluetooth peripheral device maintain connection when app is killed?
Is there a way for the bluetooth peripheral device to remain connected to iOS even after the app which was used to pair with it has been swipe killed by the user? I have - enabled Background Modes (Uses Bluetooth LE Accessory) given all the relevant permissions (Background refresh) implemented state preservation and restoration. properly handled Connection Events with proper options (CBConnectPeripheralOptionNotifyOnConnectionKey and CBConnectPeripheralOptionNotifyOnDisconnectionKey) e.g Fitbit shows as connected in bluetooth settings even after the app has been swipe killed by the user.
1
1
86
Apr ’25
Bluetooth name caching
I've enjoyed using an existing app to connect over BLE to a camera which allows for photo transfer. For some reason though early on in iOS 18, it seems the bluetooth advertising name was corrupted. As a result, the camera no longer connects to the app. I've checked on another phone that the camera connects. I was wondering how to go about clearing the bluetooth cache or maybe specifically the BLE cache. The existing app developer is non responsive and I'm assuming the issue will never be fixed. I was planning on clearing the cache within my own personal unreleased app. Just wondering if there's any cache clearing API.
5
0
77
Apr ’25
BLE timeout issue when connecting two devices on iOS 18 (but not iOS 16)
Hi, We’re developing a BLE peripheral device and encountered a connection issue when connecting two devices (Device A and Device B) simultaneously to an iOS device. Problem: On iOS 18, we are experiencing occasional BLE timeouts and disconnections when both devices are connected at the same time. On iOS 16, we did not encounter this issue under the same conditions. What we’ve tried: Adjusted the connection interval from 30ms to 15ms. This seems to have improved stability somewhat. However, we still observe intermittent timeout/disconnection issues. Questions: Are there any known changes in BLE connection handling or timing constraints in iOS 18? Are there recommended connection parameter settings (interval, latency, timeout, etc.) for multi-device BLE connections in iOS? Is there a way to debug or log more details about the disconnection reasons on the iOS side? Any guidance or suggestions would be greatly appreciated.
0
0
75
Apr ’25