Core Bluetooth

RSS for tag

Communicate with Bluetooth 4.0 low energy devices using Core Bluetooth.

Posts under Core Bluetooth tag

175 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Clear BLE service and characteristics cache
Hi, we're having trouble with a device that changes its services to do firmware updates and does not implement the Service Changed characteristic. I understand that the iPhone caches the services, is it possible to clear this cache, or is it known how long does it last? We unfortunately cannot reset the iPhone as I've seen suggested, as this is the users' phone I'm talking about. Thanks
0
1
213
Mar ’24
Detecting that a bluetooth device has been forgotten from the bluetooth setting
Hi, My app allows to connect to a bluetooth device. If the user has multiple devices he can connect all of them simultaneously, the app UI is presenting a list of all paired device. If the user open the phone bluetooth settings and forget one of the paired device, I would like to also remove it from the list of paired devices in displayed in my application. I was expecting CBCentralManager.retrievePeripherals(withIdentifiers:) to return nil if the device has been removed in the bluetooth setting but this function still return a device. Is there another solution to do that ? Thanks
0
0
263
Feb ’24
AVAudioSession currentRoute.outputs audio product port, uid
We plan to use “AVFoundation” framework, and fetch current route of .bluetoothA2DP by using AVAudioSession.sharedInstance().currentRoute.outputs to get uid of our audio headset. Then, compare audio port, uid with the one advertised in BLE manufacturer data by using CoreBluetooth framework to ensure connected audio device. Does anyone have experience of using this method in your app that works with Bluetooth audio devices?
0
0
237
Feb ’24
why is my initial view controller showing a black screen with the following errors
hi everyone. im new to xcode and wondering if anyone has any idea for what to do when your initial view controller keeps showing a black screen. ive done the following ensured Main storyboard file base name in info.pl is set to my storyboard. also under application scene manifest --> scene configurations --> application session role --> item 0 i have storyboard name as my storyboard and delegate class name as my SceneDelegate but I keep receiving this error 2024-02-13 22:42:47.452242-0500 PROJECT-NAME[11302:838011] [SceneConfiguration] Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key, but could not load class with name "SceneDelegate". 2024-02-13 22:42:47.452641-0500 PROJECT-NAME[11302:838011] [SceneConfiguration] Info.plist configuration "(no name)" for UIWindowSceneSessionRoleApplication contained UISceneDelegateClassName key, but could not load class with name "SceneDelegate". 2024-02-13 22:42:47.456532-0500 PROJECT-NAME[11302:838011] [WindowScene] There is no scene delegate set. A scene delegate class must be specified to use a main storyboard file. the initial view controller box is checked for the correct controller (HomePageController) ive added print statements to my viewDidLoad() in my HomePageController (i guess one weird thing is that i cant set 'main interface' to my main storyboard in the deployment info section) im really not sure what else to do, and any help would be really appreciated. im a beginner so all of this is a bit difficult. this is my info.pl file: https://drive.google.com/file/d/1W-KOH3BjqgfJf10n9LM5bRTYHXQYM9ER/view?usp=sharing
0
0
399
Feb ’24
BLE Pairing alert not shown after pairing failed 2-3 times
We do have an app where we try to connect via BLE to our own hardware. To trigger the pairing process we attempt a read operation on an encrypted characteristic. If the devices are note paired/bonded yet we do receive the expected CBATTErrorInsufficientEncryption Error and the native alert opens to enter the PIN. If the native pairing alert is now canceled 2-3 times the native alert will not be shown for any attempt afterwards unless I wait around 3 minutes. Is there a certain timeout for BLE devices when the system shows the pairing alert again in case it failed multiple times? I didn't find anything in that regard in the documentation.
2
0
299
Feb ’24
Running Bluetooth (BLE) tasks in background, with React Native
Currently working on an emergency app paired with a BLE device, and the desired use case is: When the device is triggered, it sends your location to your emergency contacts an API we've built. This flow works while the app is open, but we need things to obviously work while in background (while the phone is sleeping as well, of course, for emergency contexts) From what I've researched and understood, background fetches don't really work, because the intervals are a maximum of about 15 minutes, and iOS will make them less frequent based on app usage, and that window in an emergency situation isn't good enough. Having read around, I've bumped into a couple resources that suggest background bluetooth processing is possible, if I listen for a particular service being advertised, but I haven't been able to make things work so far. I wanted some help on this.
2
0
739
Feb ’24
L2CAP channel doesn't work in background
I have an app to communicate with a peripheral via L2CAP channel. Even I already enabled "Uses Bluetooth LE accessories" in "Background Mode", it still stop working when I lock the screen. Did some search and found these two posts: CBL2CAPChannel not responsive while app is backgrounded iOS Swift CoreBluetooth CBL2CAPChannel L2CAP Channel Oriented Connection Cannot Reconnect After Close From Central I am wondering if there are any solutions or work around about this. Based on the use case, I prefer to use L2CAP to transfer large data between two devices, so won't consider GATT.
1
0
493
Feb ’24
Bluetooth connection via authPlugin
Hi Team, 

I am developing a sample authPluggin which should connect to a mobile app via bluetooth connection, 
So here are the scenario

 Authplugin with Bluetooth connection shoould work on lockscreen+login 

I have created mechanism- prepared:privillaged, main, clean:Privilaged Calling corebluetoothmanager initiation at the time of prepared:privilaged mechanism I have to add my auth plugin’s mechanism before loginwindow:success mechanism

 But I always gets unauthorized = 3, from power state of bluetooth

 Note: With App, bluetooth connection is working fine, Its giving error with authPlugin How to achieve my ultimate goal, is this the right way?
2
0
398
Feb ’24
Core Bluetooth Background Modes on a package with SPM
Hi, I'm working on an SPM library that uses CoreBluetooth. Since I need to work with Bluetooth in background, I've set CBCentralManagerOptionRestoreIdentifierKey option to my instance of CBCentralManager. When I run the unit tests I encounter the following exception: Thread 1: "State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode" Of course, my demo application that I use to test the library has the bluetooth-central background mode checked. I think the issue is related to the fact that when the test target is executed, there is no associated application. Can background modes be applied to the package? How can this be resolved?
1
0
498
Feb ’24
Unable to navigate to Bluetooth Settings
I have tried below code to open [Settings(App) -> Bluetooth Settings] but it is navigating to App permission screen instead of Bluetooth Settings. I have tried to search but didn't get any latest documentation regarding it. Is there any way to do this? guard let url = URL(string: UIApplication.openSettingsURLString) else { return } if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) }
3
0
702
Feb ’24
CoreBluetooth write request receives .prepareQueueFull
I'm trying a Data value (1438 bytes) to write to a characteristic which exceeds the MTU size. When I issue the write request I receive .prepareQueueFull According to the documentation: "The prepare queue is full, as a result of there being too many write requests in the queue." The unfortunate thing is that on the I only call the write request once. peripheral.writeValue(data, for: characteristic, type: .withResponse) Any input and possible solution is welcome. Thank you in advance.
2
0
352
Feb ’24
Beacon ranging when the device is idle
We are implementing indoor positioning and proximity sensing in our iOS app using iBeacons. We have placed multiple beacons to detect the proximity of one point of interest(POI). We are using the startRangingBeacons method in the CLLocationManager class and implementing corresponding delegates to receive the ranging information. With all required foreground and background permissions granted, when a user walks from one POI to another, beacon ranging is working as expected and we are continuously receiving the sightings in the app. We have observed that, if user stops walking for a few minutes at a POI and then device automatically pauses the scan. Hence, we will not receive any beacon signals. When there is a movement, it performs beacon ranging again for a minute or so, then stops again for longer time even when user is walking. The interval between the pausing and resuming the service is not a constant. We have also observed that sometimes it takes more than 15 minutes to resume the service once the system pauses the ranging automatically. Is it an expected behavior? How long does it usually take for beacon ranging services to resume after the user starts moving? Is there any way we can reduce this delay between the pause and resume of ranging beacons? Appreciate your support
1
0
460
Feb ’24
CPU Saturation with Charts real time plotting from data received from Bluetooth
Hello everyone, I am new to Swift, it is my first project and I am a PhD Electrical Engineer student. I am designing an iOS app for a device that we are designing that is capable of reading electrical brain data and sending them via BLE with a sampling frequency of 2400 Hz. I created a Bluetooth service for the Swift app that every time it receives new data, processes it to split the different channels and add the new data to the Charts data arrays. Here is the code I've designed: func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { if characteristic.uuid == Nordic_UART_TX_CHAR_UUID { guard error == nil, let data = characteristic.value else { print("[Bluetooth] Error receiving data or no data: \(error?.localizedDescription ?? "Unknown Error")") return } DispatchQueue.global(qos: .background).async { self.processReceivedData(data) } } } func processReceivedData(_ data: Data) { var batch = [(Int, Int)]() for i in stride(from: 0, to: data.count - 4, by: 4) { let channel = Int(data[i] & 0xFF) let value = Int((Int(data[i + 3] & 0xFF) << 16) | (Int(data[i + 2] & 0xFF) << 8) | (Int(data[i + 1] & 0xFF))) - 8388608 batch.append((channel, value)) } DispatchQueue.main.async { for (channel, value) in batch { let nowTime = (Date().timeIntervalSince1970 - self.dataGraphService.startTime) let newDataPoint = DataGraphService.VoltagePerTime(time: nowTime, voltage: Double(value)/8388608, channel: "Channel \(channel - 15)") if channel == 16 { self.dataGraphService.lastX1 = nowTime self.dataGraphService.dataCh1.append(newDataPoint) } else if channel == 17 { self.dataGraphService.lastX2 = nowTime self.dataGraphService.dataCh2.append(newDataPoint) } else if channel == 18 { self.dataGraphService.lastX3 = nowTime self.dataGraphService.dataCh3.append(newDataPoint) } else if channel == 19 { self.dataGraphService.lastX4 = nowTime self.dataGraphService.dataCh4.append(newDataPoint) } } } } // DataGraphService.swift struct VoltagePerTime { var time: Double var voltage: Double var channel: String } @Published var dataCh1: [VoltagePerTime] = [] @Published var dataCh2: [VoltagePerTime] = [] @Published var dataCh3: [VoltagePerTime] = [] @Published var dataCh4: [VoltagePerTime] = [] @Published var windowSize: Double = 2.0 @Published var lastX1: Double = 0 @Published var lastX2: Double = 0 @Published var lastX3: Double = 0 @Published var lastX4: Double = 0 I also created a View that shows the real-time data from the different channels. ChartView( data: dataGraphService.dataCh1.filter { dataGraphService.getXAxisRange(for: dataGraphService.dataCh1, windowSize: dataGraphService.windowSize).contains($0.time) }, xAxisRange: dataGraphService.getXAxisRange(for: dataGraphService.dataCh1, windowSize: dataGraphService.windowSize), channel: "Channel 1", windowSize: dataGraphService.windowSize ) // ChartView.swift import SwiftUI import Charts struct ChartView: View { var data: [DataGraphService.VoltagePerTime] var xAxisRange: ClosedRange<Double> var channel: String var windowSize: Double var body: some View { RoundedRectangle(cornerRadius: 10) .fill(Color.gray.opacity(0.1)) .overlay( VStack{ Text("\(channel)") .foregroundColor(Color.gray) .font(.system(size: 16, weight: .semibold)) Chart(data, id: \.time) { item in LineMark( x: .value("Time [s]", item.time), y: .value("Voltage [V]", item.voltage) ) } .chartYAxisLabel(position: .leading) { Text("Voltage [V]") } .chartYScale(domain: [-1.6, 1.6]) .chartYAxis { AxisMarks(position: .leading, values: [-1.6, -0.8, 0, 0.8, 1.6]) AxisMarks(values: [-1.6, -1.2, -0.8, -0.4, 0, 0.4, 0.8, 1.2, 1.6]) { AxisGridLine() } } .chartXAxisLabel(position: .bottom, alignment: .center) { Text("Time [s]") } .chartXScale(domain: xAxisRange) .chartXAxis { AxisMarks(values: .automatic(desiredCount: Int(windowSize)*2)) AxisMarks(values: .automatic(desiredCount: 4*Int(windowSize)-2)) { AxisGridLine() } } .padding(5) } ) .padding(2.5) .padding([.leading, .trailing], 5) } } With these code I can receive and plot the data in real-time but after some time the CPU of the iPhone gets saturated and the app stop working. I have the guess that the code is designed in a way that the functions are called one inside the other one in a very fast speed that the CPU cannot handle. My doubt is if there is any other way to code this real-time plotting actions without make the iPhone's CPU power hungry. Thank you very much for your help!
1
0
445
Feb ’24
watchOS 10.2 Bluetooth in the background often disconnects
My watch APP needs to keep Bluetooth connected with peripherals whether it is in the foreground or background, but the results of my test show that the connection in the background is very unstable, sometimes you can keep the Bluetooth on for a day, but sometimes it will be disconnected 50 times a day, and every time it is disconnected, I will immediately initiate a reconnection, it is certain that there is no problem with the peripheral Bluetooth, because I have another iOS device that has been stably connected to the peripheral, I want to know what causes this instability, and if there is any solution, if someone can provide relevant advice, I will be very grateful
1
0
491
Feb ’24
Find My - Bluetooth Trackers = AirTags?
Hey, I've been trying to find information but haven't had any luck so far. I own two third party bluetooth trackers (not AirTags), which I've linked to Find My. Recently, I misplaced an item that had one of these trackers attached. Surprisingly, even though I was quite far away, I was still receiving updates on its location a couple hours after I lost it. I'm curious to know, does connecting a third party bluetooth tracker to Find My function in the same way as AirTags? Are there any specific documents or resources where I can learn more about this? I'm really interested in understanding how it works.
1
0
407
Jan ’24