Reedyuk / blue-falcon

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android
https://bluefalcon.dev
Apache License 2.0
328 stars 43 forks source link

iOS 13.5 Error while requested connection to device #43

Closed felislynx-silae closed 4 years ago

felislynx-silae commented 4 years ago

Hi, after invoking "falcon.connect(device)" on iOS 13.5 i get this in didDiscoverServices call 2020-06-24 07:56:19.182475+0200 App[6530:4475232] [CoreBluetooth] API MISUSE: Discovering characteristic descriptors for peripheral <CBPeripheral: 0x2802d0960, identifier = 2BF80158-F03A-AEEE-0FD4-598964BCA682, name = RPIDevice, state = connected> while delegate is either nil or does not implement peripheral:didDiscoverDescriptorsForCharacteristic:error:

Reedyuk commented 4 years ago

yeah i need to fix that, simple enough i hope.

felislynx-silae commented 4 years ago

I hope so :D i was happy that all roadblocks were cleared and this happened :(

felislynx-silae commented 4 years ago

Did little research: @kotlinx.cinterop.ObjCMethod public open fun peripheral(peripheral: platform.CoreBluetooth.CBPeripheral, didDiscoverDescriptorsForCharacteristic: platform.CoreBluetooth.CBCharacteristic, error: platform.Foundation.NSError?): kotlin.Unit { /* compiled code */ } Is present in knm, but we are unable to do override since those two have same signature and overloads are conflicting.

override fun peripheral(
            peripheral: CBPeripheral,
            didDiscoverDescriptorsForCharacteristic: CBCharacteristic,
            error: NSError?
        ) {

        }

        override fun peripheral(
            peripheral: CBPeripheral,
            didUpdateValueForCharacteristic: CBCharacteristic,
            error: NSError?
        ) {}

EDIT: This patch (changes needs to be applied to all peripheral delegate) is fixing this issue. I'm still testing (since i don't get values from characteristic now :D )

Index: library/src/iosMain/kotlin/dev/bluefalcon/BlueFalcon.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- library/src/iosMain/kotlin/dev/bluefalcon/BlueFalcon.kt (revision 4f409d6eb0af8b60fd905b7de194e075a5780afd)
+++ library/src/iosMain/kotlin/dev/bluefalcon/BlueFalcon.kt (date 1593074712000)
@@ -230,6 +230,17 @@
             }
         }

+
+        @Suppress("CONFLICTING_OVERLOADS")
+        override fun peripheral(
+            peripheral: CBPeripheral,
+            didDiscoverDescriptorsForCharacteristic: CBCharacteristic,
+            error: NSError?
+        ) {
+
+        }
+
+        @Suppress("CONFLICTING_OVERLOADS")
         override fun peripheral(
             peripheral: CBPeripheral,
             didUpdateValueForCharacteristic: CBCharacteristic,
@@ -252,6 +263,34 @@
         override fun peripheral(peripheral: CBPeripheral, didUpdateValueForDescriptor: CBDescriptor, error: NSError?) {
             println("didUpdateValueForDescriptor ${didUpdateValueForDescriptor.value}")
         }
+
+        override fun peripheral(peripheral: CBPeripheral, didModifyServices: List<*>) {
+            println("")
+        }
+
+        override fun peripheral(
+            peripheral: CBPeripheral,
+            didOpenL2CAPChannel: CBL2CAPChannel?,
+            error: NSError?
+        ) {
+            println("")
+        }
+
+        override fun peripheral(peripheral: CBPeripheral, didReadRSSI: NSNumber, error: NSError?) {
+            println("")
+        }
+
+        override fun peripheralDidUpdateName(peripheral: CBPeripheral) {
+            println("")
+        }
+
+        override fun peripheralDidUpdateRSSI(peripheral: CBPeripheral, error: NSError?) {
+            println("")
+        }
+
+        override fun peripheralIsReadyToSendWriteWithoutResponse(peripheral: CBPeripheral) {
+            println("")
+        }
     }

 }

EDIT: @Reedyuk Can confirm, it works. My bad, forgot to costumize coroutine that added delay on notification for android and it messed with ios. You can use this patch to fix ios issue :)

Reedyuk commented 4 years ago

Hi @felislynx-silae - here is a PR for the fix to stop the error message of misuse api usage. https://github.com/Reedyuk/blue-falcon/pull/44/files Let me know if this is ok and i will merge and publish.

felislynx-silae commented 4 years ago

Hi @Reedyuk I've checked your PR with devices and it is connecting and communicating. So i think, ready to merge :)

Reedyuk commented 4 years ago

released 0.7.0