Hello,
I'm using an HMSoft Bluetooth module that connects reliably to Android devices, maintaining a stable connection. However, when I try to connect it to my iPhone 12, the connection randomly disconnects after a few minutes (usually around 3 minutes). This issue occurs even when using apps like LightBlue and other BLE-based medical equipment apps, so it doesn't seem related to my app code.
Any suggestions on what I can do to prevent these unexpected disconnects? Should I change any specific settings on my iPhone or the module itself?
Core Bluetooth
RSS for tagCommunicate with Bluetooth 4.0 low energy devices using Core Bluetooth.
Posts under Core Bluetooth tag
187 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
In the YouTube video
WWDC24: Meet AccessorySetupKit | Apple
two apps are demonstrated to showcase the functionality of AccessorySetupKit. Does anyone know where I can find the source code for these demo apps?
I'm developing an app which supports for connect with an BLE device. There are some views for showing data from bluetooth. The code below for an example:
@EnvironmentObject var bleManager: BLEManager // a class implemented CBCentralManagerDelegate
var body: some View {
// bleConnected is a CBPeripheral
if let bleConnected = bleManager.bleConnected {
if let services = bleConnected.services {
ForEach(services, id:\.self) { service in
// UI for print uuid, descriptions ...
showServiceDescriptionView(services)
if let characteristics = service.characteristics {
ForEach(characteristics, id:\.self) { characteristic in
// UI for print uuid, data for each characteristic
showCharacteristicsDetailView(characteristic)
}
}
}
}
}
}
}
But it seems that Xcode Preview do not support connect to a real bluetooth device. So the preview window in Xcode will always be a empty view.
I only can see the data on the real device. But it's important for me to design UI on the preview. So are there any method to mock a fake CBPeripheral in the Previewer? Or are there any other way to achieve this?
I created a locked camera capture extension as explained in Apple's documentation.
I'm trying to explore the possibilities of using a bluetooth peripheral from that extension - anybody knows if this is possible?
The CBCentralManagerDelegate reports .unsupported in func centralManagerDidUpdateState, even if I have provided all the permissions in Info.plist.
On iPhone, we can use iBeacon to wake up the APP in the background for Bluetooth scanning connection, now we want to port the function to AppleWatch APP, but the API related to iBeacon is not applicable on watchOS, does watchOS have a similar wake up mechanism?
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
WatchKit
watchOS
Maps and Location
Core Bluetooth
iOS 17
advertisementData:
{
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = CZL2;
kCBAdvDataRxPrimaryPHY = 1;
kCBAdvDataRxSecondaryPHY = 0;
kCBAdvDataServiceUUIDs = (
FFE0
);
kCBAdvDataTimestamp = "750419647.067132";
}
iOS 18
advertisementData:
{
kCBAdvDataIsConnectable = 0;
kCBAdvDataRxPrimaryPHY = 0;
kCBAdvDataRxSecondaryPHY = 0;
kCBAdvDataServiceUUIDs = (
FFE0
);
kCBAdvDataTimestamp = "750420105.457082";
}
What should I do if the key value pair of kCBAdvDataLocalName disappears?
I have an application built with .NET MAUI that uses the CoreBluetooth API to scan for our devices. As we need extanded advertisings we want to check if the device supports it. Our problem is that the query by using the "supports" method of CBCentralManger with argument "extendedScanAndConnect" gives us not always the same result.
When called at the app start we get false (=> not supported)
When called when the state of CBCentralManager changes to "poweredOn" we get false (=> not supported)
When called later when a button to scan is pressed we get true (=> supported)
How can we get the information if extended scan is supported at startup of our app?
Hardware: iPhone 14
OS: iOS 18.0.1
We have a USB dongle that would like to connect to the iPhone for power (using USB-C). Since it is not MFi, we will then use bluetooth for communication between the dongle and an app.
When doing bluetooth pairing between the dongle and iPhone, it would be ideal to only see the dongle that is plugged into the iPhone listed in the app. This is to avoid connecting to other dongles that may be in the area.
We think this could be possible using USB descriptors. We assume the iPhone can read the USB descriptors for non-MFi dongles.
Our question is, can our app see the USB-descriptors of the dongle? Is iOS able to pass that info to the app?
Then, we could have a unique USB descriptor for each dongle and the app could only list bluetooth devices with that descriptor (effectively filtering out any other dongles in the area).
Any help and/or feedback is greatly appreciated :)
I'm encountering an issue where a specific BLE device (a Telematics Control Unit) is being discovered by some iPhone models but not others, all running the same iOS version (18.0.1).
Here's the breakdown:
Successful discovery: iPhone 11, iPhone 14 Plus, iPhone 6s
No discovery: iPhone 13, iPhone 12 mini
Firmware: The TCU firmware is up-to-date.
BLE: Bluetooth is enabled on all devices.
I've tried basic troubleshooting like restarting devices and resetting network settings, but the issue persists. Could this be related to differences in Bluetooth chipsets or antenna designs between iPhone models, even with the same iOS version? Are there any known compatibility issues between this TCU and specific iPhone models?
Any insights or suggestions for further debugging issue would be greatly appreciated!
For a personal project, I have been writing some library to interface the CoreBluetooth API with the go language. Because of what it does, that library is written in objective-C with ARC disabled.
One function I had to write takes a memory buffer (allocated with malloc() on the go side), creates an NSData object out of it to pass the data to the writeValue:forCharacteristic:type: CoreBluetooth method, and then releases the NSData as well as the original memory buffer:
void Write(CBPeripheral *p, CBCharacteristic *c, void *bytes, int len) {
NSData *data = [NSData dataWithBytesNoCopy:bytes length:len freeWhenDone:true];
[p writeValue:data forCharacteristic:c type:CBCharacteristicWriteWithoutResponse];
[data release];
}
One thing I noticed is that the retainCount for data increases during the writeValue:forCharacteristic:type: API call. It is 1 before, and 2 after. This is surprising to me, because the documentation says "This method copies the data passed into the data parameter, and you can dispose of it after the method returns."
I suspects this results in a memory leak. Am I missing something here ?
Hello,
I am planning to create an app that can transfer files to hardware devices via WiFi. With devices like GoPro, I believe the typical setup involves the GoPro creating a WiFi hotspot to which the iOS app connects, allowing file transfers. But this setup establishes a 1:1 connection between the app and the hardware.
To support multiple hardware devices simultaneously, I am considering reversing this setup: the iOS device would create a personal hotspot, and the hardware devices would connect to it. However, I have concerns about this approach:
Reliability: I have read that the personal hotspot feature on iOS devices can be unreliable, especially with non-Apple devices, which tend to disconnect frequently.
Manual Setup: There is no API to programmatically create the personal hotspot, so users would have to enable it manually in the Settings.
I can use isIdleTimerDisabled to prevent the iOS screen from going to sleep, which might help with disconnection issues. Aside from this, are there other things I can do to ensure a stable connection?
Given my limited experience with hardware connections, I am uncertain if having the iOS device act as the WiFi access point is a good design. Any advice or alternative solutions would be greatly appreciated.
Thank you in advance!
It seems that the connection failure occurs when attempting to establish GATT connections with 9 BLE devices simultaneously.
However, when connecting fewer than 8 or more than 10 devices, data can be received without issues.
Upon investigation, the following points have been identified:
This issue does not occur on iPad 10th generation.
The iPad 9th generation uses Bluetooth 4.2, while the iPad 10th generation uses Bluetooth 5.0, so this difference might be the cause.
The limitation is 9 devices per device, not per App.
The issue occurs even when trying to connect 8 BLE devices with App 1 and 1 BLE device with App 2.
It appears that the 9th device experiencing the connection failure is not receiving the result of the service discovery.
According to the PacketLogger logs, the connection itself is established, but the service discovery results are not returned.
When a 10th device is connected, the 9th device also connects successfully.
Once the 10th device connects, the service discovery results for the 9th device are returned.
The reproduction steps are as follows:
Device:
iPad 9th generation (iPadOS 17.6.1)
Procedure:
Prepare 9 BLE devices.
Connect each BLE device to the iPad one by one.
Data can be received from devices 1 through 8, but data cannot be received from the 9th device.
Hi, I am trying to write simple code that my iPhone acts as BLE peripheral (advertise packet). but i cannot see the advertisement on other devices that do scanning. What could be the cause?
Code snippet
=============
import SwiftUI
import CoreBluetooth
// 1. Conform to CBPeripheralManagerDelegate
class BLEAdvertiser: NSObject, ObservableObject, CBPeripheralManagerDelegate {
var peripheralManager: CBPeripheralManager?
// 2. Start advertising
func startAdvertising() {
peripheralManager = CBPeripheralManager(delegate: self, queue: nil)
}
// 3. CBPeripheralManagerDelegate method called when state changes
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
switch peripheral.state {
case .poweredOn:
// Define a service UUID
let serviceUUID = CBUUID(string: "1234") // Custom UUID for your service
// Create a CBMutableService
let service = CBMutableService(type: serviceUUID, primary: true)
// Add service to the peripheral manager
peripheralManager?.add(service)
// Start advertising the service
let advertisementData: [String: Any] = [
CBAdvertisementDataServiceUUIDsKey: [serviceUUID],
CBAdvertisementDataLocalNameKey: "My iPhone"
]
peripheralManager?.startAdvertising(advertisementData)
print("Started advertising!")
case .poweredOff:
print("Bluetooth is powered off.")
case .resetting:
print("Bluetooth is resetting.")
case .unauthorized:
print("Bluetooth access is unauthorized.")
case .unsupported:
print("Bluetooth is unsupported on this device.")
case .unknown:
print("Bluetooth state is unknown.")
@unknown default:
print("A new state that we don’t know about.")
}
}
// 4. Optional: Handle peripheral manager adding service
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
if let error = error {
print("Failed to add service: \(error.localizedDescription)")
return
}
print("Service added successfully!")
}
}
struct ContentView: View {
@StateObject private var bleAdvertiser = BLEAdvertiser()
var body: some View {
VStack {
Text("BLE Advertising")
.font(.largeTitle)
.padding()
Button(action: {
bleAdvertiser.startAdvertising()
}) {
Text("Start Advertising")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
}
I would like to know the maximum number of Bluetooth peripherals that can be connected to a mobile phone. Is there a specific limit on the number of Bluetooth peripherals, or what is the connection number related to
I have a mobile phone and a number of peripherals. I want to know the maximum number of peripherals that can be connected to a mobile phone. Is there any clear explanation for this, or what is the relationship between the number of connections
I’m working on an iOS app that uses Bluetooth Low Energy (BLE) to communicate with a peripheral device. Currently, we scan by service ID and successfully connect in the background.
Would it be acceptable (and within Apple's guidelines) to poll data from the device every 5 seconds while in the background?
Or is it required to have the BLE device notify?
There is a small probability that the Bluetooth connection will be accidentally disconnected after Bluetooth is connected. Error message: CBErrorDomain Code=6 “The connection has timed out unexpectedly.” UserInfo={NSLocalizedDescription=The connection has timed out unexpectedly.
I am developing an application that allows you to interact with people on your local network.
I have a view called ProfileView() which has has identifiers inside of it such as that build up the profile for each person.
Essentially, what I want to do is discover people who are on this app on your local network, or who are nearby to you based on bluetooth. I do not want to use a server, as I would like this to be an application that does not require internet access to function. Also if possible, I would like a toggle to allow yourself to be discovered in the background, even if not using the app.
Any ideas how to do this? Also, is there any better way to do this instead of Bluetooth and Local Network?
Thank you
Possible code chunks needed:
Discover nearby bluetooth users
Discover nearby network users
Toggle for discovery
Toggle for background discovery (while not using app)
Share profile (mainly just text and a profile image)
I’m currently developing an app that communicates with a BLE dongle. When I swipe up to close the app on my phone, both the phone app and the CarPlay app are terminated. From the CarPlay interface, I can relaunch the app. My question is: Can CarPlay establish a connection with a BLE dongle when the phone app is fully closed or not running in the background?
Topic:
App & System Services
SubTopic:
Processes & Concurrency
Tags:
IOBluetooth
CarPlay
Core Bluetooth
Hi there,
I'm working on a product which needs to pair with an iOS device (only iPad and iPhone) via Bluetooth. I already have the device pairing and operating fully with android or Windows hosts and have implemented BLE. Obviously, iOS isn't as simple as those for pairing. The product type is not listed under the MFi accessories.
The question I have is what hardware and or firmware needs does the product needs to fulfil in order to pair/bond fully. I've seen some devices have a MFi security chip, some need to be manufactured in a MFi approved facility, I've no idea on the firmware requirements. We're starting the process of joining the MFi program too. So:
Do I need the security chip?
Where is the pairing process documented?
Can I use BLE or do I need to use classic Bluetooth or core Bluetooth?
Any help would be greatly appreciated because I'm kind of lost.
Thanks, Louis