Skip to content

SkashEU/knfc

Repository files navigation

KNFC: Kotlin Multiplatform Near Field Communication Library

KNFC is a lightweight Kotlin Multiplatform library designed to simplify common NFC tag reading and writing operations across Android and iOS, abstracting away the platform-specific complexities of NfcAdapter and CoreNFC.

Getting Started

Initialization and Configuration

The library uses KNFC to set up all required parameters before reading or writing. Configuration is split into two main blocks: Common (shared configuration) and Platform (Android/iOS specific configuration).

val knfc =
        KNFC {
            withConfiguration {
                requireNdefSupport(true)
                requireTechnologies(NfcTech.Ndef)
                withTimeout(10.toDuration(DurationUnit.SECONDS))
            }
            withPlatformConfiguration {
                configurePlatform()
            }
        }     

Core API Usage

Once the client is built, you can use the functions from the KNFC interface in your shared code:

Method Type Description
read(): Flow<NFCTag> Shared Starts an NFC reading session and returns a Flow of discovered NFCTag objects.
write() Shared Suspends until an NDEF message is successfully written to a discovered tag.

Configuration Details

Method Type Description
withTimeout(duration: Duration) Shared Sets the global timeout for the NFC session.
requireTechnologies(vararg techs: NfcTech) Shared Adds one or more required NFC technologies for tag filtering.
requireNdefSupport(isRequired: Boolean) Shared A quick way to ensure the detected tag must contain valid NDEF data.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages