Core Bluetooth

RSS for tag

Communicate with Bluetooth 4.0 low energy devices using Core Bluetooth.

Core Bluetooth Documentation

Posts under Core Bluetooth tag

207 Posts
Sort by:
Post not yet marked as solved
0 Replies
21 Views
Hi. I'm strictly following the documentation about requesting value for a characteristic containing large data, as it states: Note: Use notifications to send a single packet of data to subscribed centrals. That is, when you update a subscribed central, you should send the entire updated value in a single notification, by calling the updateValue:forCharacteristic:onSubscribedCentrals: method only once. Depending on the size of your characteristic’s value, not all of the data may be transmitted by the notification. If this happens, the situation should be handled on the central side through a call to the readValueForCharacteristic: method of the CBPeripheral class, which can retrieve the entire value. Source: (https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH4-SW1) I'm doing just that. I request the characteristic value with a single request: - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {     if (error)     {         [self disconnectWithError:error];         return;     }     [service.characteristics enumerateObjectsUsingBlock:^(CBCharacteristic * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)     {         NSString * chUUID = obj.UUID.UUIDString; if ([chUUID isEqualToString:Test_Char])         {             self.testCh = obj;             [peripheral readValueForCharacteristic:obj];         }     }]; } Then on PeripheralManager side I'm implementing the delegate method as suggested: - (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveReadRequest:(CBATTRequest *)request {     if ([request.characteristic.UUID isEqual:self.testCh.UUID])     {   // test         if (request.offset > self.testCh.value.length)         {             [self.peripheralManager respondToRequest:request                                           withResult:CBATTErrorInvalidOffset];             return;         }         NSInteger length = self.testCh.value.length - request.offset;         request.value = [self.testCh.value subdataWithRange:NSMakeRange(request.offset,                                                                         length)];         [self.peripheralManager respondToRequest:request                                       withResult:CBATTErrorSuccess];         return;     }     [self.peripheralManager respondToRequest:request                                   withResult:CBATTErrorInvalidHandle]; } code-block The delegate method get called multiple times, but always with offset 0. Also, peripheral side, I'm receiving without error a truncated value with unexpected length. (552) Any clues? Is the documentation not being updated with a newest implementation? Thx
Posted
by D-One SH.
Last updated
.
Post not yet marked as solved
1 Replies
871 Views
I am learning Core Bluetooth to improve my general skills and marketability for new jobs. I have written a MacOS app that acts as a CBPeripheralManager and an iOS app that acts as a CBCentralManager. I have gotten the Peripheral to stream small data chunks to the Central just fine.Now I am looking to learn how to send larger data amounts. I have seen the sample code for sending data to subscribers in chunks and am in the process of porting that to Swift. But the CoreBluetooth docs also say: "Note: Use notifications to send a single packet of data to subscribed centrals. That is, when you update a subscribed central, you should send the entire updated value in a single notification, by calling the updateValue:forCharacteristic:onSubscribedCentrals: method only once. Depending on the size of your characteristic’s value, not all of the data may be transmitted by the notification. If this happens, the situation should be handled on the central side through a call to the readValueForCharacteristic: method of the CBPeripheral class, which can retrieve the entire value." https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html#//apple_ref/doc/uid/TP40013257-CH4-SW1What I can't figure out is how to use `readValueForCharacteristic:` properly for a peridoically-updating characteristic. Is that possible, actually? I can't seem to subscribe to it to know when ot updates and then call `readValueForCharacteristic` as that endlessly tries to read the data but only gets the partial data. I tried sending an update notification from the Peripheral on one characteristic at the same time as I updated the data on a second characteristic. Then when the central gets the first characteristic update, it tries reading the second charcteristic but it gets `nil` for the value. But if I implement peripheralManager:didReceive readRequest:, and print the value of the characteristic, the Peripheral thinks it has data.I have also noticed that `readValueForCharacteristic:` also causes subscritptions to time out after 30 seconds or so, if I get this working do I need to resubscribe to services after doing it?Peripheral code is at https://github.com/natebirkholz/BluetoothTransmitter/tree/MultipleCharacteristicsCentral code is at https://github.com/natebirkholz/BluetoothTest/tree/MultipleCharacteristics
Posted Last updated
.
Post not yet marked as solved
0 Replies
39 Views
I have an iOS App as peripheral which advertises packets.      NSDictionary *advertise = @{CBAdvertisementDataLocalNameKey : shortName, CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:uuidA]]};          [self.manager startAdvertising:advertise]; Then, my other centratl app will scan and filter by the same serviceUUID. [self.manager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:uuidA] options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @(true)}]; Now, we want to change the ServiceUUID (uuidA -> uuidB), but we hope that the old version of the central app can still scan for the new peripheral app, so I need do multi-advertisement of BLE. // 1 NSDictionary *advertise = @{CBAdvertisementDataLocalNameKey : shortName, CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:uuidA], [CBUUID UUIDWithString:uuidB]]}; [self.manager startAdvertising:advertise]; // 2 NSDictionary *advertise = @{CBAdvertisementDataLocalNameKey : shortName, CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:uuidA]]}; [self.manager startAdvertising:advertise]; NSDictionary *advertise = @{CBAdvertisementDataLocalNameKey : shortName, CBAdvertisementDataServiceUUIDsKey: @[[CBUUID UUIDWithString:uuidB]]}; [self.manager2 startAdvertising:advertise]; However, these two implementations, on the central side, it can always scan only one broadcast packet. Can somebody suggest any method to do this task? From the central (scanner) app, I should get two different advertisements.
Posted
by Colin1994.
Last updated
.
Post not yet marked as solved
1 Replies
52 Views
Hi, I have a certified and qualified BLE device that is a Central role. When I try to connect it to an iOS device as a peripheral (using 3rd party application such as nRF Connect) I am able to create pairing and bonding, but for some reason the iOS device disconnect immediately after the encryption and authentication process success. I have heard one explanation for this issue, but I haven't found it in any documentation: iOS device as a peripheral will disconnect if he sees that there are no requests from the Central side. is it true? I would be happy to be inferred to the relevant documentation about this issue. Thank you
Posted
by Addi_K.
Last updated
.
Post not yet marked as solved
0 Replies
74 Views
I have an App that connects to an IOT device via Bluetooth. I gave it the proper permissions in the info.plist file, and it works fine when I run it from XCode, is able to connect to and communicate with the IOT device via bluetooth. However, when I installed the App on another device via TestFlight, it does not work despite having all the same permissions and the exact same code. I do not know how to debug it since in Dev it works fine. Does anyone have any idea how I can track down what is happening?
Posted Last updated
.
Post not yet marked as solved
0 Replies
59 Views
Hello What is the best framework for indoor geofencing (with iBeacons devices)? Would the SensorKit framework be any good? I'm trying to build an indoor geofencing app that uses UWB or BLE devices. I am thinking of the SensorKit framework because it is used for research and studies and I am looking for the best way to realize indoor geofencing (preferably using UWB devices). The app should also work while it's in the background. Thank you!
Posted
by Jad-T.
Last updated
.
Post marked as solved
57 Replies
31k Views
Hi, I am an application developer for Mac. Our application uses bluetooth to connect to our hardware devices. Since the upgrade to MacOS 12.0.1 Monterey Bluetooth is broken customer wide. Hence pairing works but our driver cannot connect (code worked for MacOS 10.7 - 11.3). The internet reports a lot of Bluetooth issues related to Broadcom BT on Monterey and the Bluetooth Framework has changed significantly by Apple. Where can I find detailed information about Apple's Bluetooth changes ? Should I just wait until Apple fixes this from their side ? Any other guidance is appreciated. Thank you?
Posted
by pkiman.
Last updated
.
Post not yet marked as solved
0 Replies
65 Views
Calling the Bluetooth GetMessage function for a message that was sent via Bluetooth, the returned BMessage contains an incorrect folder path to the message. The Event Report returns the correct folder path when the message is successfully sent. Scenario: Connect to Bluetooth MAP services (MNS and MAS). Call Bluetooth "PushMessage" function. Get 'Name Header' for the Message Handle. MAP-Event-Report received with Type of SendingSuccess and Folder equal to "telecom/msg/sent". Use "SetFolder" to navigate to Sent folder. Call "GetMessage" with the Message Handle (the handle is the same for both the event report and PushMessage function). The BMessage response has a folder of "telecom/msg/inbox" BMessage: BEGIN:BMSG VERSION:1.0 STATUS:UNREAD TYPE:SMS_GSM FOLDER:telecom/msg/inbox NOTIFICATION:1 BEGIN:VCARD VERSION:2.1 FN;CHARSET=UTF-8:[Contact] N;CHARSET=UTF-8:[Contact] TEL:3: END:VCARD BEGIN:BENV BEGIN:VCARD VERSION:2.1 FN;CHARSET=UTF-8:[Contact] N;CHARSET=UTF-8:[Contact] TEL:[Phone Number] END:VCARD BEGIN:BBODY CHARSET:UTF-8 LANGUAGE:UNKNOWN LENGTH:[Some Length] BEGIN:MSG iOS is the worst. END:MSG END:BBODY END:BENV END:BMSG Set Folder to telecom: 85-00-20-02-00-01-00-13-00-74-00-65-00-6C-00-65-00-63-00-6F-00-6D-00-00-4C-00-03-CB-08-60-59-D0 Set Folder to msg: 85-00-18-02-00-01-00-0B-00-6D-00-73-00-67-00-00-4C-00-03-CB-08-60-59-D0 Setting Folder to sent: 85-00-1A-02-00-01-00-0D-00-73-00-65-00-6E-00-74-00-00-4C-00-03-CB-08-60-59-D0 Calling GetMessage function: 83-00-44-01-00-23-00-44-00-33-00-42-00-43-00-34-00-45-00-39-00-31-00-30-00-35-00-41-00-41-00-34-00-43-00-32-00-00-42-00-10-78-2D-62-74-2F-6D-65-73-73-61-67-65-00-4C-00-09-14-01-01-0A-01-00-CB-08-60-59-D0 Section 3.1.4 of the Bluetooth Specification states: "telecom/msg/sent: This folder shall contain messages that were successfully sent to the network by the MSE, at least during the period of the current MAP session. In particular these messages have been queued in the 'Outbox' folder before sending and are shifted by the MSE to this folder after transmission." Apple is also nice enough to not include any additional contacts when the text message is part of a group text. This has been made unnecessarily difficult for developers to use and what's worse, it seems intentional.
Posted Last updated
.
Post not yet marked as solved
0 Replies
61 Views
From what I understand, iOS supports receiving a BLE advertisement packet while the app is running in the background if: The app defines "bluetooth-central" in the UIBackgroundModes section of info.plist The service UUID is given when calling the centralManager.scanForPeripherals function The service UUID is transmitted in the actual advertisement packet, and not the scan response My question is this: if the peripheral uses BLE 5.0 extended advertisements, and the service UUID that the iOS device is scanning for is in the extended packet, will the app get a didDiscover peripheral callback while in background mode? https://developer.apple.com/videos/play/wwdc2019/901/
Posted
by eejake.
Last updated
.
Post not yet marked as solved
2 Replies
121 Views
We used Bluetooth Connection in our project, but in iOS 16 beta version, we found that the first Connection pairing can be connected normally, but the Connection will fail again after disconnection. The system HCI log shows "Encryption Change completion-Connection Timeout". I would like to ask what changes iOS 16 system version has made to bluetooth connection pairing that cause such trouble for our use.
Posted Last updated
.
Post not yet marked as solved
3 Replies
2.6k Views
I had the intention of designing an audio routing app for the iPhone. My goal was to pair my iPhone (ME344LL/A) to a computer (MBP 11,1) and send audio over Bluetooth to the iPhone.My problem is that my computer wont pair to my iPhone as an audio device. I looked into the Bluetooth profiles and it appears that if I can manually set the profile on my iPhone then my computer can pick it up.This must be possible, maybe not by default but I must be able to override the iOS defaults. Thank you for any help anyone can provide!
Posted
by evanman.
Last updated
.
Post not yet marked as solved
0 Replies
69 Views
I use CoreBluetooth to develop bluetooth application, but now I use scanPeripheralWithService, gave the UDID and then the method was never invoked `State : Powered On State: Powered on )  is writing  to /var/mobile/Containers/Data/Application/7A8F6CF8-E1E8-49E4-AEC1-450A30DC9071/Documents/29-06-2022.log Discovered %s at %d nil -70 Bluetooth Manager --> didDiscoverPeripheral, RSSI:-70 data:["kCBAdvDataRxPrimaryPHY": 1, "kCBAdvDataRxSecondaryPHY": 0, "kCBAdvDataTimestamp": 678161943.056277, "kCBAdvDataIsConnectable": 0]-- peripheral:<CBPeripheral: 0x280b91360, identifier = F87EDA74-A896-1320-AEE4-4DCA51F2FD51, name = (null), mtu = 0, state = disconnected> advertisementData is ["kCBAdvDataRxPrimaryPHY": 1, "kCBAdvDataRxSecondaryPHY": 0, "kCBAdvDataTimestamp": 678161943.056277, "kCBAdvDataIsConnectable": 0] Bluetooth Manager --> didDiscoverPeripheral, RSSI:-70 data:["kCBAdvDataRxPrimaryPHY": 1, "kCBAdvDataRxSecondaryPHY": 0, "kCBAdvDataTimestamp": 678161943.056277, "kCBAdvDataIsConnectable": 0]-- peripheral:<CBPeripheral: 0x280b91360, identifier = F87EDA74-A896-1320-AEE4-4DCA51F2FD51, name = (null), mtu = 0, state = disconnected>)  is writing  to /var/mobile/Containers/Data/Application/7A8F6CF8-E1E8-49E4-AEC1-450A30DC9071/Documents/29-06-2022.log Discovered %s at %d nil -50 Bluetooth Manager --> didDiscoverPeripheral, RSSI:-50 data:["kCBAdvDataTimestamp": 678161943.088981, "kCBAdvDataRxSecondaryPHY": 0, "kCBAdvDataIsConnectable": 0, "kCBAdvDataRxPrimaryPHY": 1]-- peripheral:<CBPeripheral: 0x280b914a0, identifier = 36954FD9-A8B4-B112-EBA2-844EAC80B32C, name = (null), mtu = 0, state = disconnected> advertisementData is ["kCBAdvDataTimestamp": 678161943.088981, "kCBAdvDataRxSecondaryPHY": 0, "kCBAdvDataIsConnectable": 0, "kCBAdvDataRxPrimaryPHY": 1]
Posted Last updated
.
Post not yet marked as solved
0 Replies
99 Views
I was wondering if it is possible to use the bluetooth API on iPadOS to let an app become an emulated "bluetooth speaker/car". I want to make an app where an iPhone or Android phone can connect to it via bluetooth so the app can play the audio from the phone, and receive and handle calls just like a car can play audio and handle calls and display call information via bluetooth. I would also like to know if the app could also get contact information from the phone over bluetooth. If it is possible to do so, how? I would love a friendly nudge in the right direction :)
Posted
by krirogn.
Last updated
.
Post not yet marked as solved
0 Replies
97 Views
I am making a chat app and have researched how to send data from one phone to another phone for the messages but it has the Central and peripherals which is one way only. From what I can find, there is no way for both of them to be able to send data to each other. If anyone knows how to fix this please help!
Posted
by CrazyH.
Last updated
.
Post not yet marked as solved
0 Replies
80 Views
Dear Everyone! I am using RxBluetooth Kit library to connect bluetooth to peripheral devices. But now, when I read data from 1 characteristics, in call back I did not read another characteristics. My code is as follows: viewDidAppearSubject .take (1) .flatMap {self.bluetoothProvider.getValueUpdates (for: charator2102)} .subscribe ( onNext: { if $ 0 == "2103" { self.read2103 () } print ($ 0) }, onError: {_ in self.showError ()} ) .disposed (by: disposeBag) When I receive data of charator2102, I cannot read more data of charactor2103 anymore. Hope everyone help me! Thanks very much!
Posted
by hungnx5.
Last updated
.
Post not yet marked as solved
1 Replies
117 Views
Any developer has experience in CTKD? I saw it was mentioned in WWDC 2019 (https://developer.apple.com/videos/play/wwdc2019/901), and it stated that there would be a sample project from documentation (https://developer.apple.com/documentation/corebluetooth/using_core_bluetooth_classic). But I could not find further information on it.
Posted Last updated
.
Post not yet marked as solved
0 Replies
73 Views
I am very new to the Bluetooth/BLE world and have been using multiple different online resources to help learn my way through it. I want to be able to list the discovered devices in a list, and upon clicking on the device in the list I want to connect to that device. All the guides show connecting to the device after scanning. What is the best approach to store the peripherals so that I can connect to the device of choice from the list? I can post my current code if it helps! Thanks!
Posted
by Qcook1221.
Last updated
.
Post not yet marked as solved
0 Replies
112 Views
I am developing an ios Bluetooth app with Swift and UIKIT, The app scans for a specific Bluetooth service and connects to it. Once the connection is established, I discover the services and characteristics of the connected peripheral. The peripheral has two characteristics. One for writing to the peripheral and the other for notifying and reading data from the device. Writing to the peripheral works fine but reading from the device gives the error shown below. Error Domain=CBATTErrorDomain Code=2 "Reading is not permitted." UserInfo={NSLocalizedDescription=Reading is not permitted.} But I have the same app developed in swift and SwiftUI and both writing and reading work fine with the same peripheral connected. Can anyone please explain to me why this is happening? Thank you
Posted
by lord99.
Last updated
.
Post not yet marked as solved
1 Replies
195 Views
Dear I want to ask the functionality of below function API: knownPeripherals = [myCentralManager retrievePeripheralsWithIdentifiers:savedIdentifiers to consider the following case: if A peer BLE device had been connected and all the services and characteristics had been discovered and read. and saved this peripherals object with the NSobject Identity. and then IOS disconnected with this peer BLE device. after a few hours or days or minutes, if call retrievePeripheralsWithIdentifiers can retrive the Peripherals object, does it mean that all the services uuid and characteristics attribute are available from the cached as well? just connect to the ble device identified by this peripherals object, no need to find services and characteristics for second time.
Posted
by laodeng.
Last updated
.