Core Bluetooth

RSS for tag

Communicate with Bluetooth 4.0 low energy devices using Core Bluetooth.

Posts under Core Bluetooth tag

173 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

BLE5 extended advertising not working with iOS 17
I am using nRF52840, and have set up BLE 5 extended advertising. I was able to connect with the nRF Connect app to nrf52840 device using iPhone 11, 12, 13 running iOS 16. Recently after updating to iOS 17, I can only discover the BLE device, but can't manage to connect to the device from the app. I can only connect to the device via iPhone 11, running iOS 17. However, all the other later versions of iPhone do not permit me to connect with the nrf device. As a test switching to BLE4 advertising, devices are both discoverable and connectable, on these same iPhone versions running iOS 17. I need to use BLE5 and can't switch to BLE 4 for production release. Also, the same devices can be both discovered and connected to, using Android phones that support BLE 5. While trying to connect with iPhone running iOS 17, I don't get a response to the connection from the BLE5 advertisement. This was confirmed by Wireshark capture while trying to connect on the iPhone. Nordic has confirmed that the issue is not on their side and hence would like your help to investigate this further.
1
1
626
Dec ’23
Music volumen down bluetooth after iOS 17.2
I am detecting problems with the volume level with the Bluetooth connection after the iOS 17.2 update. Before this problem persisted on the iPhone 11 and the iPhone 15 Pro, after the 17.2 update it seems that the problem was fixed on the iPhone 11 but still It persists on the iPhone 15 Pro. I have never had problems with the volume level in my car, but something Apple has changed that continues to affect it. How can it be corrected? Thank you very much for your support. I did a test with the same song and the same volume level (maximum volume on the smartphone and volume 12 on my Suzuki Swift) and these were the decibels results obtained. The Iphone 11 and 15 Pro has updated to iOS 17.2
0
0
435
Dec ’23
Capturing BLE Scan Parameters
Hello, I've been trying to debug a Bluetooth issue with an app I'm working with. Is there a way to capture the LE Set Scan Parameters HCI event? I've downloaded the Bluetooth debug profile and managed to capture the HCI traffic using the Packet Logger tool. The problem is that I don't see the Scan Parameters event occurring. I can see Advertisement parameters being set (which is odd that the iPhone is doing so, even with Airdrop and BLE disabled). I can see lots of Advertising Reports which indicate that the device is scanning; but I can never catch when the parameters are set for that. I've attached a sample log of me just toggling the Bluetooth off and on. Any insight is appreciated. Thank you
1
0
340
Dec ’23
CoreBluetooth and peripheral UUID
I have a custom framework that allows you to handle all Bluetooth actions, such as connect, scan, etc. Additionally, I have two applications using this framework: a test app and a real app. I'm trying to implement auto-reconnection for turning Bluetooth off/on and out of range. While it works well in my test app, it doesn't in the real app. Here is my logic: Firstly, I scan for a peripheral with a specific service UUID: manager.scanForPeripherals(withServices: [self.targetUuid], options: scanOptions) As a result, I have a CoreBluetooth callback response: func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) Then I connect to the peripheral: connect(cbPeripheral, options: options) And as a result: func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) After that, I save the UUID as a String. Then, I try to disconnect the peripheral from the phone (turn BT off/on or go out of range) and connect back. I've investigated different behaviours and found that in my test app, I have the same peripheral UUID even after disconnection, but in the real app, the UUID changes. I found this: The UUID will stay constant for a peripheral with randomized addresses for paired devices only for the lifetime of the pairing. If a device is not paired, according to the LE Privacy rules (RRA), the UUID will change as a peer unit is neither capable nor supposed to track a device across changing addresses. And this: Connection attempts do not time out (as stated in the Apple documentation: [link]). Just be sure to also keep a reference to the peripheral object; otherwise, the connection gets canceled. Here is my logic for reconnection in case of being out of range: centralManager(_:didDisconnectPeripheral:error:) [ERROR] - Peripheral was disconnected error -> Optional(Error Domain=CBErrorDomain Code=6 "The connection has timed out unexpectedly." UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.}) connect(cbPeripheral, options: options) My question is: What can affect UUID changing? Do I need to store a whole Peripheral Device object instead of UUID string?
1
0
584
Dec ’23
Core Bluetooth Bug
Hi developers, I am trying this code to read from 3 bluetooth beacon: class BeaconScanner0: NSObject, CBCentralManagerDelegate { var centralManager: CBCentralManager! var shouldContinueScanning = true // Add a flag to control scanning var i=0 var BeaconRSSI = [0, 0, 0] override init() { super.init() centralManager = CBCentralManager(delegate: self, queue: nil) } func centralManagerDidUpdateState(_ central: CBCentralManager) { if central.state == .unauthorized { print("Bluetooth access is unauthorized. Requesting permission...") centralManager.delegate = self } else if central.state == .poweredOn { print("Bluetooth is powered on. Scanning for beacons...") // Start scanning for all peripherals centralManager.scanForPeripherals(withServices: nil, options: nil) } else { print("Bluetooth is not powered on or available.") } } func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi: NSNumber)->[Int] { print("BeaconRSSI: \(BeaconRSSI)") if let name = peripheral.name { if name.contains("BlueCharm") { if name.contains("79") { BeaconRSSI[0] = rssi.intValue // i += 1 } if name.contains("67") { BeaconRSSI[1] = rssi.intValue // j += 1 } if name.contains("96") { BeaconRSSI[2] = rssi.intValue // k += 1 } } } return BeaconRSSI } } it got back the error (bug!) like below: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'String does not represent a valid UUID' *** First throw call stack: (0x1b361e69c 0x1ab8d7c80 0x1b2b7cdd8 0x1d8062634 0x1d80628a8 0x1d8025130 0x1d8024cd8 0x104a95140 0x104a8baa0 0x104a8b970 0x104a8bac4 0x104a8b818 0x104a8caf0 0x1057c2b34 0x1057c4690 0x104a8cb54 0x104a8cb6c 0x1057c2b34 0x1057c4690 0x104a8cc0c 0x104a8cc68 0x1057c2b34 0x1057c4690 0x104a8cd28 0x104a8cfc0 0x1057c2b34 0x1057c4690 0x104a8d064 0x104a8d61c 0x1057c2b34 0x1057c4690 0x104a8d6c4 0x104a93d98 0x104a93c74 0x1b80c709c 0x1b839a624 0x1b8ac2b68 0x1b8ac0300 0x1b8b308e8 0x1b8b30948 0x1b5794fe0 0x1b4ba9aa8 0x1b4ba9630 0x1b4bafb60 0x1b4ba8e3c 0x1b5a7e03c 0x1b35691b8 0x1b35679ac 0x1b35658ac 0x1b3565478 0x1f6abe4f8 0x1b598f360 0x1b598e99c 0x1b83a04b8 0x1b83a02fc 0x1b8010e90 0x104a9eb3c 0x104a9ec84 0x1d629ddcc) libc++abi: terminating due to uncaught exception of type NSException *** Assertion failure in -[CBUUID initWithString:safe:], CBUUID.m:219 could anyone help me with this problem. Thanks beforehand.
1
0
370
Dec ’23
When iOS17 has a bug and cannot record audio, play the audio to a Bluetooth device
let session = AVAudioSession.sharedInstance() do { try session.setCategory(AVAudioSession.Category.playback) try session.setActive(true) //playAndRecord <AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)> //playback <AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)> print(session.currentRoute.outputs) } catch { print(error) } when I ssession.setCategory(AVAudioSession.Category.playback) audio play output a2dp ble devices. session.currentRoute.outputs print bellow `<AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)> when I ssession.setCategory(AVAudioSession.Category.playAndRecord) output <AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)> BluetoothA2DPOutput is gone. but it is normal in ios15-16. Is there any solution? I want to record audio and play music at the same time. And the music is output from the Bluetooth speaker
1
0
478
Dec ’23
How to make sound output from Bluetooth instead of speakers in IOS 17
When I set the AVAudioSessionCategory avAudioSessionCategory: AVAudioSessionCategory.playAndRecord, sound to come out of the built-in speaker instead of Bluetooth headphones。ios17 。It is normal in IOS 16 or 15 final session = await AudioSession.instance; await session.configure(AudioSessionConfiguration( avAudioSessionCategory: AVAudioSessionCategory.playAndRecord, avAudioSessionCategoryOptions:AVAudioSessionCategoryOptions.allowBluetooth | AVAudioSessionCategoryOptions.allowBluetoothA2dp, avAudioSessionMode: AVAudioSessionMode.defaultMode, avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy, avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none, androidAudioAttributes: const AndroidAudioAttributes( contentType: AndroidAudioContentType.music, flags: AndroidAudioFlags.none, usage: AndroidAudioUsage.media, ), androidAudioFocusGainType: AndroidAudioFocusGainType.gain, androidWillPauseWhenDucked: true, )); How to make sound output from Bluetooth instead of speakers in IOS 17? How to make sound output from Bluetooth instead of speakers in IOS 17?
1
0
463
Dec ’23
CBPeripheral gets stuck in connecting/disconnecting states
I work on an app that operates a HW device that acts as a BLE peripheral. Our BLE code stack has not changed much since 2017 and has been working very well over the years. We recently started seeing a lot of customer complaints and bad App Store reviews that the device was not working. I have been investigating this for several weeks now and I'm struggling to narrow down the cause, but it seems to be a change in iOS. With the same app and device FW the issue is almost exclusively seen on iOS 17.x even though ~40% of our user base is still on iOS 16.x. From my investigation what I see is the CBPeripheral getting stuck in connecting state. When it is in this state advertisements are seen in our app, and other apps are able to connect to the device (nRF Connect for example). If I cancel the connection the CBPeripheral then gets stuck in the disconnecting state. I can only toggle between these two states and it will remain like this for days. I have found that initializing a new CBCentralManger will sometimes "fix" the issue. However, about 50% of the time the new CBCentralManager comes up in the unknown state so CoreBluetooth as a whole seems to be in a weird state. More effective is killing the app and relaunching. But even then sometimes the CBPeripheral immediately gets stuck again and it takes multiple killing/launching the app to get back in a working state. Few points that seem relevant: App has central and peripheral background modes enabled. App uses state restoration, though most of the times I see this issue there was not a state restore that happened. To reproduce the issue the app needs to be in the background for some amount of time, and it happens on foregrounding. We will in some cases scan/connect in the background, but I have reproduced this issue without that. Is anyone else seeing this issue or have ideas what might be causing it?
5
3
893
5d
Clarification on MFi Certification Capabilities for Enhanced Bluetooth Functionality
Hello Apple Developer Community, I represent a team working on an iOS application that interacts with a Bluetooth Low Energy (BLE) module in vehicles. We're exploring advanced functionalities and have a couple of queries: Automatic PIN Handling: Is there a method for our app to programmatically input a PIN for Bluetooth pairing, bypassing the usual popup prompt? We aim to streamline the user experience by eliminating manual PIN entry. Programmatic Bond Management: Can our app directly "forget" a paired Bluetooth device without requiring the user to manually do so in the iOS settings? This feature would significantly enhance our app's usability. MFi Certification Benefits: Would obtaining MFi certification enable any of the above functionalities, or provide us with additional APIs or capabilities to manage Bluetooth connections more effectively? We appreciate any guidance or insights you can provide on these matters. Understanding these capabilities is crucial for the development of our application. Thank you in advance for your assistance. Best regards,
0
0
231
Dec ’23
Missing multiple imports in CoreBluetooth.framework
I've been repeatedly getting the following error when compiling my project: Unknown class name 'CBCentralManagerDelegate'; did you mean 'CBCentralManager' Within CoreBluetooth.framework my CoreBluetooth.h is as follows: /*! * @header * @file CoreBluetooth.h * @framework CoreBluetooth * * @discussion Bluetooth Low Energy framework * * @copyright 2011 Apple, Inc. All rights reserved. */ #ifndef _CORE_BLUETOOTH_H_ #define _CORE_BLUETOOTH_H_ #endif #import <CoreBluetooth/CBDefines.h> #if __OBJC__ #import <CoreBluetooth/CBCentralManager.h> #import <CoreBluetooth/CBPeripheralManager.h> #import <CoreBluetooth/CBPeripheral.h> #import <CoreBluetooth/CBCentral.h> #import <CoreBluetooth/CBService.h> #import <CoreBluetooth/CBCharacteristic.h> #import <CoreBluetooth/CBDescriptor.h> #import <CoreBluetooth/CBError.h> #import <CoreBluetooth/CBUUID.h> #import <CoreBluetooth/CBAdvertisementData.h> #import <CoreBluetooth/CBATTRequest.h> #endif Specifically I'm missing #import <CoreBluetooth/CBCentralManagerDelegate.h> as well as the relevant class within my Headers folder. Does anyone know why this might be the case? I'm using Xcode 15.1 Beta 3.
1
0
298
Nov ’23
visionOS as a BLE peripheral: CBMutableService init unavailable
I'd like to have the visionOS be a peripheral, in BLE terminology. This is required, as the hardware that will act as the central cannot act as peripheral (don't ask). The problem is some initializers I seem to need to advertise a mutable service are not available: 1. 'init(type:primary:)' has been explicitly marked unavailable here (CoreBluetooth.CBMutableService) It would seem that this isn't supported yet. Is this currently possible some other way, or will it be possible in the future?
2
0
309
Nov ’23
Android Device is not Listing For iphone Devices for coreBluetoothScanning
Hello Apple Support Team, As per the business requirement, we have to communicate and exchange data chunks between applications running on iPhones and Android-based or Android phones through Bluetooth interface. We have achieved the requirement through IP/Wifi communication. We are trying to connect to Android and iPhone devices via Bluetooth through an iOS application. We carried out Bluetooth implementation using CoreBluetooth libraries. Below are the findings done by our development team: Core Bluetooth Library Implementation           Importing Core Bluetooth Library in BTConnectionManager class, which uses CBCentralManagerDelegate, CBPeripheralDelegate, CBCentralManager, CBPeripheral as peripheral, [CBPeripheral] array as peripherals array. Using the below methods: centralManagerDidUpdateState, centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber), centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral), peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?), peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: Service, error: Error?) we are able to scan and connect to BLE devices Findings: We were able to get the list of low-energy devices like Airpods, Earphones and Bluetooth music devices. But Not able to scan Bluetooth high-energy devices like PAX / Android Phones   Please suggest to us the approach to make the Android running devices listed through the Core Bluetooth library. Thanks & Regards
0
0
556
Nov ’23
Bluetooth Low Energy HID Gamepad PnP not accepted by iOS devices
Dear support We are developing a Bluetooth Low Energy HID Gamepad and are having issues connecting it to iOS devices (iPhone). Pairing is always successful. The issue is related to the PnP ID used. 1. If we use a PnP ID for a gamepad currently on the market - like a Google Stadia - there is no issue. The Gamepad connects (pairs) with the iPhone and is recognised in the iPhone "settings->general->game controller" Also if a "Game Controller Tester" APP is installed on the iPhone this works ok. 2. If we use our own PnP the Gamepad connects (pairs) but iPhone does not recognise it in "settings->general->game controller" . Also the "Game Controller Tester" APP does not work. The question is :- Is there something we need to do with our own PnP for it to be recognised by iOS devices. For info - on Android and Windows our PnP is recognised ok - we can control a Game Controller APP with it. The issue is only with Apple iOS devices. Any help would be welcome. Thanks JESP
3
0
523
Nov ’23
CBConnectPeripheralOptionEnableAutoReconnect not working
Hi, I am trying to use the new parameter option CBConnectPeripheralOptionEnableAutoReconnect when connecting to a peripheral. However I am receiving the error One or more parameters were invalid. I tested on iOS 17.1. I try to connect using this code: centralManager.connect(peripheral, options: [CBConnectPeripheralOptionEnableAutoReconnect: true]) Am I missing something? It looks like an iOS bug.
1
0
383
Nov ’23
Authorization-plugin: Invoke the Core Bluetooth APIs from the plugin
Hello, is it possible to interact with a nearby device through Bluetooth LE, from the authorization plugin? Currently, I have: a plugin bundle, registered with the authorization mechanisms; a daemon that I have set up to contain all the business logic added the com.apple.security.device.bluetooth entitlement to the daemon package, to allow Bluetooth communication; registered the daemon through LaunchDaemons so that it is managed by launchd And I'm using XPC to communicate between the plugin and the daemon. When I send the request to the daemon to scan for peripherals, I get a TCC error: 0xd5a Error 0x23e5 161 0 tccd: [com.apple.TCC:access] Refusing TCCAccessRequest for service kTCCServiceBluetoothAlways from client Sub:{...} in background session The above error seems to suggest that I can't grant the bluetooth permission from the daemon itself, is there a recommended way to grant permissions before running it? And if granted, would I be able to utilize the framework successfully from the logon screen? Other options I have tried: Invoking the framework directly from the plugin, which failed. Probably because the Security agent process isn't entitled to communicate via Bluetooth and that it would require changing the host process entitlements plist, which I don't have access to? 🤔 Attempting to use a launch agent in lieu of a daemon, with proper entitlement, but that didn't work either. Probably because launch agents are loaded after the user has successfully logged in and I was invoking it before? 🤔 And lastly, I looked into the possibility of utilizing Privacy Preference MDM payload to grant access, but it seems like the MDM options do not include Bluetooth support. Is there any other way to accomplish this? Thank you!
2
0
469
Nov ’23
Determine if a device support BLE Extended Advertising
I need to receive extended BLE advertising packets. I have my device advertising extended advertising packets (verified on third party app and embedded devices), however, I do not receive any of these packets in the centralManager didDiscover callback. I tried to see if my devices support extended advertising via the code below, however this check is always negative on both an iPad Mini 5th gen and an iPhone 14. Both of these should support BLE 5.0 features, correct? Is there some changes I need to make for my CBCentralManager scanning or callbacks to receive extended advertising data? if #available(iOS 13.0, *) { if CBCentralManager.supports(CBCentralManager.Feature.extendedScanAndConnect) { print("This device supports BLE Extended Advertising."); } else { print("This device does NOT BLE Extended Advertising."); } } else { print("Not iOS 13"); }
0
0
364
Nov ’23
How to pair specific BLE devices with designated iOS devices with multiple iOS devices and BLE devices in the same vicinity?
We need a method to uniquely pair 4 phones to 4 Bluetooth LE devices (each phone connects to one BLE device). They will all be operating at the same time, in the same room. On Android we store a list of MAC addresses of the BLE devices and the phone app lets the user select which device to connect. On Apple, MAC addresses can not be read when peripherals are discovered, so we are stuck. The preferred Apple approach seems to be to connect to a BLE device, then read its serial number, and check if it is the correct device. However, if we have 4 BLE devices all active at the same time, we could get stuck in an infinite loop where the phone keeps reconnecting to the same BLE device, finding it has the wrong serial number, disconnecting, ad infinitum. The "UUID encrypted MAC address" seems like a bad workaround. It would require all 4 users to wait for each other while they uniquely pair. If anyone accidentally left their BLE device on while another person was pairing, things could break. How do we solve this problem?
0
0
439
Oct ’23