question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kotlin KMM dev.bluefalcon.BluetoothUnknownException: Unknown error happened

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Reedyukcommented, Apr 9, 2022

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.

0reactions
nilskasseckertcommented, Apr 9, 2022

Thanks a lot!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found