Core Bluetooth

RSS for tag

Communicate with Bluetooth 4.0 low energy devices using Core Bluetooth.

Posts under Core Bluetooth tag

176 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

ios swift application instance time alive
Hi all, I have created an application that uses location services and bluetooth services. Inside AppDelegate using significant location changes I am assigning a new instance of CBCentralManager like this How long this instance is staying alive? I am noticing that it may last even five days but I am not sure which parameters affect this? class AppDelegate: UIResponder, UIApplicationDelegate ,CLLocationManagerDelegate,CBCentralManagerDelegate,UNUserNotificationCenterDelegate { private static var centralManager : CBCentralManager! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if let keys = launchOptions?.keys { if keys.contains(.location) { AppDelegate.centralManager = CBCentralManager(delegate: self, queue: nil) locationManager.requestAlwaysAuthorization() locationManager.allowsBackgroundLocationUpdates = true locationManager.pausesLocationUpdatesAutomatically = false } } return true } func centralManager(_ central: CBCentralManager, didDiscover peripheral:CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { AppDelegate.centralManager.connect(peripheral, options: nil)* } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { AppDelegate.centralManager.connect(peripheral, options: nil) } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { AppDelegate.centralManager.connect(peripheral, options: nil) } }
0
0
292
Aug ’23
iOS 17 Bluetooth DFU bug
We were using this library (https://github.com/NordicSemiconductor/IOS-DFU-Library) from Nordic Semiconductor to perform OTA firmware update. Everything works perfectly until iOS 17 came out. Some of our users are on iOS 17 beta program, they experienced firmware update issues with it. In our testing, the update progress can initiate without any issue, however, at some random point during the update (sometimes 1%, sometimes 60%, it's totally random) the progress gets stuck. The firmware update wasn't an issue on iOS 16 and below, so we suspect that it's a bug on the new OS, not on the library.
2
1
1.4k
Oct ’23
Connecting to a Bluetooth Peripheral on the application level only.
Hi there! My team and I are currently working on developing an iOS application that connects to our proprietary hardware using Bluetooth technology. During our development process, we encountered an issue related to the central manager's behavior. Specifically, the central manager only disconnects the peripheral device from the app level, leaving the connection active at the system level. In the context of the cancelPeripheralConnection discussion, one of the reasons cited for not allowing the app to disconnect the peripheral from the system is as follows: Because other apps may still have a connection to the peripheral, canceling a local connection doesn’t guarantee that the underlying physical link is immediately disconnected (source) For our situation, the challenge lies in the fact that no other application should have access to this specific peripheral. It is designed exclusively for our system's use. To address this, our current workaround involves sending a custom disconnect command to our device via a designated characteristic. However, we are keen to explore if there's a way to establish the initial connection to the peripheral in a manner that avoids creating a system-level connection altogether. Thank you for your assistance! Liz
2
0
412
Sep ’23
What is Service UUID for bluetooth devices like Apple Airpods.
I am working on a Application which requires to identify whether any airpods are connected to Ipad. I have used retrieveConnectedPeripherals(withServices:) in CoreBluetooth framework (https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals ) and tried to fetch the bluetooth connected devices list. But this method mandates to provide ServiceUUID list of the devices that needs to be fetched. Based on available information on various forums , I tried to used below UUIDS for fetching bluetooth connected airpods from this doc (https://www.bluetooth.com/specifications/assigned-numbers) but none of them worked for me. retrieveConnectedPeripherals() returns empty list everytime eventhough airpods are connected to Ipad during testing. Audio Stream Control service 0x184E, Automation IO service 0x1815, Broadcast Audio Announcement service 0x1852, Broadcast Audio Scan service 0x184F, Common Audio service 0x1853, Generic Media Control service 0x1849, Media Control service 0x1848, Microphone Control service 0x184D, Volume Control service 0x1844, Audio Input Control service 0x1843 Other UUIDs tried : 0x1108 0x1112 0x111E 0x111F Would like to know correct UUID for apple Airpods. Thanks in advance! Let me know if any other information is required.
1
0
1.2k
Sep ’23
Multi Anchor Nearby Interaction
Scenario: We have a museum where each exhibit has a UWB BLE accessory. A user moves around the museum with their phone application in the background. Once a user enters an exhibit area (Determined by UWB distances) a background task is initiated (audio/notification/widget). The Question: In our current understanding of the protocol, the user must pair to each exhibit anchor beforehand, significantly impairing the user experience and bloating their Bluetooth-paired device list. Is it possible now or potentially in the future to not require pairing for pre-approved devices? Alternatively, pairing to a hub that acts as an intermediary between the phone and accessories also seems like an appropriate compromise.
1
0
681
Mar ’24
Get List/Count of bluetooth connected devices to Ipad
I am working on a Application which requires to identify list of bluetooth paired devices connected to Ipad. I have used scanforperipherals(withServices:nil) in CoreBluetooth framework but I see state is always disconnected even though device is connected to iPad. output : <CBPeripheral: 0x281d000, identifier = 31EADDCE-5DBC-E57F-84DB-1488C20460F9, name = AirPods Pro, mtu = 0, state = disconnected> Later used Retrieveconnectedperipherals method (https://developer.apple.com/documentation/corebluetooth/cbcentralmanager/1518924-retrieveconnectedperipherals ) and tried to fetch the Bluetooth connected devices list. But this method mandates to provide ServiceUUID list of the devices that needs to be fetched which doesn't help me as I need to fetch all devices list. I understand EAAccessoryManager framework gets the list of MFI devices but it mandates to provide protocol names of devices. let connectedDevices = EAAccessoryManager.shared().connectedAccessories as? [EAAccessory] Would like to know if there is any way to fetch the list/count of Bluetooth devices connected to iPad without providing UUIDs/Protocol names. Thanks in advance! Let me know if any other information is required.
0
0
508
Sep ’23
BLE Cycling Power Service for Watch Workout
Hi, I have an app that implements the Cycling Power Service 1.1, https://www.bluetooth.com/de/specifications/specs/cycling-power-service-1-1/ As expected, I can select this app as a Health Device in the Bluetooth settings of my Apple Watch. However, when I run the BLE app on the paired iPhone, the Apple Watch does not detect the BLE Service as a Health Device! Is this a bug, or is it designed this way? If so, is there another API where I can send power meter data from iOS to a running Watch Workout?
2
0
578
Sep ’23
Bluetooth Device Implementation
Hello all, I am interested in trying to develop a short-medium range (>100 meters) tracking device for a hobby project in order to gain some literacy in mobile phone software, and have a few questions. I am new to working with anything iOS so please correct me in any mistakes I make in this query. Is RFID or Bluetooth better for tracking and implementation on iOS? How difficult is device implementation into iOS and apps such as find my iPhone? How would one go about it? If I wanted a tracking device to send notifications based on location/distance from another device, could I do that with Apples framework or would I have to create my own app? What programming language would be used in this sort of endeavor? Would C++ work or does iOS use different ones? Thanks in advance, any and all advice is greatly appreciated.
1
0
584
Sep ’23
What CoreBluetooth physical layer?
We have a process in our iPhone app that uses CoreBluetooth to transfer a large amount of data over time using Bluetooth LE. Now I'm looking for ways to speed up this process. From what I have gathered, there is no way to set a preferred phyaical layer (PHY) for CoreBluetooth. How does iOS determine the best PHY to use? Is there any way I can influence it? I was not able to locate any documentation from Apple mentioning "physical layer" or "phy" for CoreBluetooth, only a brief GitHub Issue for a multiplatform networking library that discussed setting a "PreferredPhy" for iOS.
0
0
525
Oct ’23
Generate 64 bytes using ECDSA SHA 256 using pem file in XCode
// here is the code snippet func generateSignatureWithPEMFile(data: Data, privateKeyPEM: String) -> Data? { let privateKeyBIO = BIO_new(BIO_s_mem()) let privateKeyPEMData = privateKeyPEM.data(using: .utf8) _ = privateKeyPEMData?.withUnsafeBytes { buffer in BIO_write(privateKeyBIO, buffer.baseAddress, Int32(buffer.count)) } let privateKey = PEM_read_bio_PrivateKey(privateKeyBIO, nil, nil, nil) let signature = UnsafeMutablePointer.allocate(capacity: 64) var signatureLength: UInt32 = 64 let ctx = EVP_MD_CTX_new() EVP_DigestInit(ctx, EVP_sha256()) _ = data.withUnsafeBytes { buffer in EVP_DigestUpdate(ctx, buffer.baseAddress, buffer.count) } EVP_SignFinal(ctx, signature, &signatureLength, privateKey) EVP_MD_CTX_free(ctx) EVP_PKEY_free(privateKey) BIO_free(privateKeyBIO) return Data(bytes: signature, count: Int(signatureLength)) } // usage let dataToSign = Data(hex: key)! let stringDataToSign = Data(stringToSign.utf8) if let signature = generateSignatureWithPEMFile(data: dataToSign, privateKeyPEM: privateKeyPEM) { let signatureHex = signature.map { String(format: "%02x", $0) }.joined() print("Signature (Hex): (signatureHex)") peripheralsConnected!.writeValue(signature, for: characteristic, type: .withResponse) } else { print("Failed to generate the signature.") } but i am getting 70 bytes or 71 bytes or 72 bytes in the debug console @eskimo pls help me !! i am stuck on this point from many days, any help will be appreciated, thanks in advance!!
0
0
302
Oct ’23
WatchOS CoreBluetooth maximum peripheral connections
I have an app running on WatchOS. How many BLE peripherals can my app connect to at the same time? If the number of peripheral objects is limited in some way, is the limit imposed on each instance of CBCentralManager? Or is the limit imposed on each app? I have a use case that would require four BLE peripheral connections. Is tis possible? I have another use case that would require 6 BLE peripheral connections. Is this possible?
1
0
377
Oct ’23
BLE MIDI auto connection/pairing
Hi there, We're developing a product which has a BLE module that advertises itself as a BLE MIDI device. The goal for our iOS app is to have the phone auto-connect to the device, which it already bonded with. Exactly like headphones; Bond one time, and everytime the headphones turn on, the phone automaticly pairs/connects to the headphones. At the moment, a new connection is required every time the the device turns on and advertises. I've read on the apple BLE documentation page, that from iOS 16 or later "the system automatically reconnects Bluetooth Low Energy (BLE) MIDI peripherals when powered on, if the device supports pairing. Previously, it was necessary to use Audio MIDI Setup to establish BLE MIDI connections." ( https://developer.apple.com/documentation/coremidi/midi_bluetooth/ ) However, neither our iPhones that run iOS 16+ or macOS 13+ devices re-connect to the BLE MIDI device. How can I achieve this? As per official BLE documentation, pairing is initiated by the central device (smartphone etc.) and the peripheral (BLE MIDI device) should simply store the MAC address + security information of the central device that it is currently bonded with.
0
0
647
Oct ’23
application(_:didFinishLaunchingWithOptions:) always invoked with nil bluetooth centrals in iOS 13
Hi, my app needs to use BLE in background mode and I have set up everything according to the CoreBluetooth docs and everything is running as expected except for application(_:didFinishLaunchingWithOptions:), which always returns a nil launchOptions. The reason why I want to use the bluetooth centrals keys in launchOptions is that I want to differentiate whether the central is newly created or restored from the background activities, so that I can have different init/reinit paths. But without the launchOptions, I am not sure how to achieve that. Some people said since iOS13 the launchOptions have been migrated to the scene delegate, but there is no equivalent option for the bluetooth centrals, does anyone know how to resolve it? Thanks.
0
0
248
Oct ’23
Connecting to a bluetooth device while app is terminated
Hello everyone! I'm currently working on an iOS app developed with Swift that involves connecting to a specific ble (Bluetooth Low Energy) device and exchanging data even when the app is terminated or running in the background. I'm trying to figure out a way to wake up my application when a specific Bluetooth device(uuid is known) is visible and then connect to it and exchange data. Is this functionality achievable? Thank you in advance for your help!
4
0
1.1k
Oct ’23
fatal error: Index out of range...
class CalculatorViewModel : NSObject, ObservableObject, Identifiable { var id = UUID() @Published var output = "Disconnected" @Published var connected = false @Published var databasePath = String() enum itemType : Int{ case angle = 1 case degree = 2 case grip1 = 3 case grip2 = 4 } struct test_Array: Identifiable { var id = UUID() var time: String var swingNum : Int var dataSeqInSwing: Int var timeStampInSeq: Double var itemType: Int var value: Double } @Published var testDBdata = [test_Array] () ..... private var centralManager: CBCentralManager? func connectCalculator() { output = "Connecting..." centralQueue = DispatchQueue(label: "test.discovery") centralManager = CBCentralManager(delegate: self, queue: centralQueue) } .... func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { ..... if characteristic.uuid == outputCharUUID, var data = characteristic.value { ..... DispatchQueue.main.async() { for index in tupleSets { strItemSets = index.components(separatedBy: ",") ....... var itemN = 1 for indexStr in strItemSets { self.golfDBdata[numDB].dataSeqInSwing = countItem. <= Error self.golfDBdata[numDB].itemType = itemN self.golfDBdata[numDB].value = Double(strItemSets[itemN]) ?? 0.0
5
0
674
Oct ’23
xcode 17 failure with real device iOS 17 in flutter
When running the flutter project, the following message appears: Failed to verify code signature of /var/installd/Library/Caches/com.apple.mobile.installd.staging/temp.payaqa/extracted/Runner.app : 0xe8008015 (A valid provisioning profile for this executable was not found.) Verify that the Developer App certificate for your account is trusted on your device. Open Settings on the device and navigate to General -> VPN & Device Management, then select your Developer App certificate to trust it. But, when I connected the iPhone show to trust. I can run other projects without problem with Switf directly. But when I tried to run using Flutter, show me this message. Macos: Sonoma 14 Flutter: channel Stable: 3.13.6 Xcode 15: 15A240d
6
1
2k
Oct ’23
Problem with access to bluetooth
HI, i am new to IOS development. I work with Xcode 15.0, and IOS 17.0.3 I want to write an app to control a small robot using bluetooth. I get the following error message : This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSBluetoothAlwaysUsageDescription key with a string value explaining to the user how the app uses this data. However, in my infpo.plist, i have the following settings : <dict> <key>NSBluetoothAlwaysUsageDescription</key> <array> <string>This application requires Bluetooth to connect to the roboter</string> </array> <key>UIApplicationSceneManifest</key> <dict> <key>UIApplicationSupportsMultipleScenes</key> <false/> <key>UISceneConfigurations</key> <dict> <key>UIWindowSceneSessionRoleApplication</key> <array> </array> </dict> </dict> </dict> The project section looks like this : Any ideas ?
1
0
910
Oct ’23