Kotlin KMM dev.bluefalcon.BluetoothUnknownException: Unknown error happened
See original GitHub issueDescribe the bug I have included the library via KMM. I have added the dependency in commonMain. Now I built a wrapper around the class in shared code in Kotlin. This looks like this:
class BluetoothManager(private val blueFalcon: BlueFalcon) {
private val bluetoothDelegate = BluetoothManagerDelegate()
init {
blueFalcon.delegates.add(bluetoothDelegate)
}
override fun isScanning(): Boolean {
return blueFalcon.isScanning
}
override fun startScanning() {
if (isScanning()) {
return
}
blueFalcon.scan()
}
....
}
In iOS I start the scanning in the ViewModel via the following code:
init() {
bluetoothService = BluetoothManager(blueFalcon: Blue_falconBlueFalcon(context: UIView(), serviceUUID: nil))
bluetoothService.bluetoothManager.startScanning() --> The Crash is happening here
isScanning = bluetoothService.bluetoothManager.isScanning()
}
}
The app crashes immediately. Why? The crash report contains following:
Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: dev.bluefalcon.BluetoothUnknownException: Unknown error happened
at 0 shared 0x108b2e1db kfun:kotlin.Throwable#<init>(kotlin.String?){} + 99
at 1 shared 0x108b26d0f kfun:kotlin.Exception#<init>(kotlin.String?){} + 95
at 2 shared 0x108f0f86b kfun:dev.bluefalcon.BluetoothUnknownException#<init>(kotlin.String){} + 95
at 3 shared 0x108f0f957 kfun:dev.bluefalcon.BluetoothUnknownException#<init>(kotlin.String?;kotlin.Int;kotlin.native.internal.DefaultConstructorMarker?){} + 215
at 4 shared 0x108f151bb kfun:dev.bluefalcon.BlueFalcon#scan(){} + 491
at 5 shared 0x108f2a28b kfun:eu.ces.connect_multi.manager.bluetooth.BluetoothManager#startScanning(){} + 171
at 6 shared 0x10907b307 objc2kotlin.3043 + 135
To Reproduce Ue the same code as I
Expected behavior That all is working
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- Kotlin KMM
- iOS 15
Issue Analytics
- State:
- Created a year ago
- Comments:15 (7 by maintainers)
Top Results From Across the Web
Help with ios BluetoothUnknownException · Issue #26 - GitHub
First, thank you for upgrading library to latest Kotlin version. ... BluetoothUnknownException - Unknown error happened
Read more >Get started with Kotlin Multiplatform Mobile
Kotlin Multiplatform Mobile (KMM) is an SDK designed to simplify the development of cross-platform mobile applications.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah i know the issue now.
You cannot perform a scan immediately after instantiating a BlueFalcon object in iOS, this is due to the way corebluetooth works. Related to this issue: https://stackoverflow.com/questions/25932366/cbmanager-state-always-unknown
I have fixed your example where its not working to make the scan fire afterwards, with a scan button. https://github.com/AppSupporter/bluetooth-bug/pull/1
This is not really a bug with blue falcon, more an issue with the way core bluetooth works, unfortunately. I am going to close this issue.
Thanks a lot!