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

CentralManager does not get the changed localNameKey at advertisement[CBAdvertisementDataLocalNameKey]
I scan my ble device with the code below. centralManager.scanForPeripherals(withServices: [connectionServiceUUID], options: nil) and the call back method is called when the device is scaned. func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { ... } I have 2 questions with the value of advertisementData[CBAdvertisementDataLocalNameKey] from the callback method. Suppose there is connections, and the localNameKey of the device is A. When it is scanned and connected at first, the advertisementData[CBAdvertisementDataLocalNameKey] I get is not A but something else. Here, if I do the same then I get A. Now, I change the localNameKey of the device to B. And when it is scanned, the advertisementData[CBAdvertisementDataLocalNameKey] is still A, and I do the same, now it is B. Why? When the screen is off, advertisementData[CBAdvertisementDataLocalNameKey] never changes, why?
0
0
207
Jan ’24
centralManager does not get the changed advertisementData[CBAdvertisementDataLocalNameKey] when the screen is off
I have a BLE device and the centralManger scans with "centralManager.scanForPeripherals(withServices: [connectionServiceUUID], options: nil)" Then func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { ... } is called. Here, I could get the advertisementData[CBAdvertisementDataLocalNameKey]. I have set my BLE device to change its local name key for every connections. The BLE communication is repeated in the background.(scan, connect, stop scan, disconnect, ... etc) It works well, but when the screen is off, the value of advertisementData[CBAdvertisementDataLocalNameKey] in didDiscover does not change. Why?
0
0
282
Jan ’24
Searching for an example of a proper iBeacon implementation for iOS 17
Hello, I'm looking for an end-to-end example project that shows a correct implementation for the new iBeacon CoreLocation APIs in iOS 17.0 (CLMonitor, etc.). Ideally the example would cover background waking as that is the area in which I am facing the largest challenges. Perhaps there's an Open Source project or an official Apple example? Thanks for pointing me in the right direction. Jeremy
3
0
624
Jan ’24
objectC, swift, swiftUI, Bluetooth classic, Bluetooth Low Energy, IOS deploy version? Users Number?
objectC program: iOS all : iPhone ~ swift program. : iOS 13 ~ : iPhone 6s ~ swiftUI Program : iOS 13 ~ : iPhone 6s ~ bluetooth classic : ~ iPhone 4s Bluetooth Low Engery : iPhone 5 ~ are All above content right? i am making iOS app with swiftUI app, and Bluetooth Low Energy. after making app, i found that my app can run on greater than iOS13 , iPhone 6s. how many is ther number of above iPhone6s User ?
0
0
443
Dec ’23
corebluetooth Bluetooth cannot connect to airpods
Hello everyone: I used corebluetooth, but currently I cannot connect Airpods headphones. details as following: Unable to scan to unconnected devices. If the device is already linked, it can be searched, but the connection cannot be made successfully. I searched Google for related posts but couldn't find a website that can solve the problem. I need to ask if there are any relevant restrictions on Airpods or if there are other real solutions that I can link to. thank you all.
0
0
278
Dec ’23
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
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