Have you tried making it non-private? Also, I’m se...
# ios
j
Have you tried making it non-private? Also, I’m seeing that classes extending Obj-C classes need to be
final
. https://kotlinlang.org/docs/native-objc-interop.html#subclassing-swift-objective-c-classes-and-protocols-from-kotlin
g
I also have the same error as Carlo, although the func tagReaderSessionDidBecomeActive is called correctly, however the func tagReaderSession(session: NFCTagReaderSession, didDetectTags: List<*>) gives the error “Delegate does not implement -tagReaderSessiondidDetectTags method” . Could this be a recognized bug? I read that with swift the delegate implementation code is this “tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) ” but in kotlin it is different “tagReaderSession(session: NFCTagReaderSession, didDetectTags: List<*>)”
j
Ah yeah you might have to change the ObjC name with an annotation. The compiler might be mangling that.
c
Hi, thanks for your time, but: @ObjCName is not applicable on overrides
👍 1
ide said
j
Shoot. Sorry!
c
any help is appreciated
g
thanks for the help, any suggestion is welcome, also because I haven’t found any example of using nfc for ios with kotlin multiplatform
x
I too encounter the same issue
Copy code
-[NFCTagReaderSession didDetectTags:connectedTagIndex:]:163 Delegate does not implement -tagReaderSession:didDetectTags: method
But my kotlin delegate looks like
Copy code
class NFCTagReaderSessionDelegate() : NSObject(), NFCTagReaderSessionDelegateProtocol {
  override fun tagReaderSession(session: NFCTagReaderSession, didDetectTags: List<*>) {
  }
}
seems to be a compiler issue? 🤔
ah so turns out you just need to keep a reference to your delegate
Copy code
actual class Nfc {
  lateinit var delegate: NFCTagReaderSessionDelegate

  @OptIn(ExperimentalForeignApi::class)
  actual fun ndef(): Flow<NfcDataExchangeFormat> = callbackFlow {
    delegate = NFCTagReaderSessionDelegate(scope = this)
    val session = NFCTagReaderSession(
      pollingOption = NFCPollingISO14443 or NFCPollingISO15693 or NFCPollingISO18092,
      delegate = delegate,
      queue = dispatch_get_main_queue(),
    )
    session.alertMessage = "Hold your iPhone near an NFC tag to pair with the device."
    session.beginSession()
    awaitClose { session.invalidateSession() }
  }
}