From cf550fdeb733af9417dba68b6bd2db55270a1db5 Mon Sep 17 00:00:00 2001 From: okadan <46291090+okadan@users.noreply.github.com> Date: Sun, 5 Mar 2023 10:50:25 +0900 Subject: [PATCH] Create v4.0.0 release --- .gitignore | 1 - .metadata | 18 +- CHANGELOG.md | 185 +- LICENSE | 2 +- README.md | 83 +- android/build.gradle | 32 +- android/src/main/AndroidManifest.xml | 2 +- .../plugins/nfcmanager/NfcManagerPlugin.kt | 509 ++++ .../dev/flutter/plugins/nfcmanager/Pigeon.kt | 1611 +++++++++++ .../plugins/nfcmanager/NfcManagerPlugin.kt | 348 --- .../flutter/plugins/nfcmanager/Translator.kt | 150 -- .../nfcmanager/NfcManagerPluginTest.kt | 11 + example/.gitignore | 1 - example/README.md | 13 + example/android/app/build.gradle | 24 +- .../android/app/src/debug/AndroidManifest.xml | 3 +- .../android/app/src/main/AndroidManifest.xml | 7 +- .../plugins/nfcmanagerexample/MainActivity.kt | 6 + .../plugins/nfcmanagerexample/MainActivity.kt | 21 - .../app/src/profile/AndroidManifest.xml | 3 +- example/android/build.gradle | 5 +- example/android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 34 +- example/ios/Podfile | 3 + example/ios/Podfile.lock | 6 +- example/ios/Runner.xcodeproj/project.pbxproj | 266 +- .../xcshareddata/xcschemes/Runner.xcscheme | 13 +- .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin 564 -> 295 bytes .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin 1283 -> 406 bytes .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin 1588 -> 450 bytes .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin 1025 -> 282 bytes .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin 1716 -> 462 bytes .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin 1920 -> 704 bytes .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin 1283 -> 406 bytes .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin 1895 -> 586 bytes .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin 2665 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin 2665 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin 3831 -> 1674 bytes .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin 1888 -> 762 bytes .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin 3294 -> 1226 bytes .../Icon-App-83.5x83.5@2x.png | Bin 3612 -> 1418 bytes example/ios/Runner/Base.lproj/Main.storyboard | 13 +- example/ios/Runner/Info.plist | 12 +- example/ios/Runner/Runner.entitlements | 10 - example/ios/RunnerTests/RunnerTests.swift | 9 + example/lib/main.dart | 135 +- example/pubspec.lock | 102 +- example/pubspec.yaml | 4 +- ios/Classes/NfcManagerPlugin.h | 4 - ios/Classes/NfcManagerPlugin.m | 15 - ios/Classes/NfcManagerPlugin.swift | 802 ++++++ ios/Classes/Pigeon.swift | 1804 +++++++++++++ ios/Classes/SwiftNfcManagerPlugin.swift | 767 ------ ios/Classes/Translator.swift | 161 -- ios/nfc_manager.podspec | 2 +- lib/nfc_manager.dart | 1 - lib/nfc_manager_android.dart | 12 + lib/nfc_manager_ios.dart | 6 + lib/platform_tags.dart | 12 - lib/src/channel.dart | 3 - lib/src/nfc_manager/nfc_manager.dart | 236 +- lib/src/nfc_manager/nfc_ndef.dart | 297 --- lib/src/nfc_manager_android/nfc_manager.dart | 111 + .../nfc_manager_platform.dart | 40 + lib/src/nfc_manager_android/pigeon.dart | 3 + lib/src/nfc_manager_android/pigeon.g.dart | 2033 ++++++++++++++ lib/src/nfc_manager_android/tags/iso_dep.dart | 81 + .../tags/mifare_classic.dart | 169 ++ .../tags/mifare_ultralight.dart | 105 + lib/src/nfc_manager_android/tags/ndef.dart | 120 + .../tags/ndef_formatable.dart | 65 + lib/src/nfc_manager_android/tags/nfc_a.dart | 76 + lib/src/nfc_manager_android/tags/nfc_b.dart | 61 + .../nfc_manager_android/tags/nfc_barcode.dart | 46 + lib/src/nfc_manager_android/tags/nfc_f.dart | 76 + lib/src/nfc_manager_android/tags/nfc_v.dart | 61 + lib/src/nfc_manager_android/tags/tag.dart | 31 + lib/src/nfc_manager_ios/nfc_manager.dart | 342 +++ .../nfc_manager_ios/nfc_manager_platform.dart | 33 + lib/src/nfc_manager_ios/pigeon.dart | 3 + lib/src/nfc_manager_ios/pigeon.g.dart | 2368 +++++++++++++++++ lib/src/nfc_manager_ios/tags/felica.dart | 315 +++ lib/src/nfc_manager_ios/tags/iso15693.dart | 283 ++ lib/src/nfc_manager_ios/tags/iso7816.dart | 117 + lib/src/nfc_manager_ios/tags/mifare.dart | 115 + lib/src/nfc_manager_ios/tags/ndef.dart | 144 + lib/src/platform_tags/felica.dart | 282 -- lib/src/platform_tags/iso15693.dart | 371 --- lib/src/platform_tags/iso7816.dart | 97 - lib/src/platform_tags/iso_dep.dart | 62 - lib/src/platform_tags/mifare.dart | 97 - lib/src/platform_tags/mifare_classic.dart | 173 -- lib/src/platform_tags/mifare_ultralight.dart | 81 - lib/src/platform_tags/ndef_formatable.dart | 51 - lib/src/platform_tags/nfc_a.dart | 58 - lib/src/platform_tags/nfc_b.dart | 54 - lib/src/platform_tags/nfc_f.dart | 58 - lib/src/platform_tags/nfc_v.dart | 54 - lib/src/translator.dart | 337 --- pigeon/android.dart | 231 ++ pigeon/ios.dart | 374 +++ pigeon/pigeon_android.dart | 166 ++ pigeon/pigeon_ios.dart | 266 ++ pubspec.yaml | 16 +- 105 files changed, 13153 insertions(+), 4241 deletions(-) create mode 100644 android/src/main/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPlugin.kt create mode 100644 android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt delete mode 100644 android/src/main/kotlin/io/flutter/plugins/nfcmanager/NfcManagerPlugin.kt delete mode 100644 android/src/main/kotlin/io/flutter/plugins/nfcmanager/Translator.kt create mode 100644 android/src/test/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPluginTest.kt create mode 100644 example/android/app/src/main/kotlin/dev/flutter/plugins/nfcmanagerexample/MainActivity.kt delete mode 100644 example/android/app/src/main/kotlin/io/flutter/plugins/nfcmanagerexample/MainActivity.kt delete mode 100644 example/ios/Runner/Runner.entitlements create mode 100644 example/ios/RunnerTests/RunnerTests.swift delete mode 100644 ios/Classes/NfcManagerPlugin.h delete mode 100644 ios/Classes/NfcManagerPlugin.m create mode 100644 ios/Classes/NfcManagerPlugin.swift create mode 100644 ios/Classes/Pigeon.swift delete mode 100644 ios/Classes/SwiftNfcManagerPlugin.swift delete mode 100644 ios/Classes/Translator.swift create mode 100644 lib/nfc_manager_android.dart create mode 100644 lib/nfc_manager_ios.dart delete mode 100644 lib/platform_tags.dart delete mode 100644 lib/src/channel.dart delete mode 100644 lib/src/nfc_manager/nfc_ndef.dart create mode 100644 lib/src/nfc_manager_android/nfc_manager.dart create mode 100644 lib/src/nfc_manager_android/nfc_manager_platform.dart create mode 100644 lib/src/nfc_manager_android/pigeon.dart create mode 100644 lib/src/nfc_manager_android/pigeon.g.dart create mode 100644 lib/src/nfc_manager_android/tags/iso_dep.dart create mode 100644 lib/src/nfc_manager_android/tags/mifare_classic.dart create mode 100644 lib/src/nfc_manager_android/tags/mifare_ultralight.dart create mode 100644 lib/src/nfc_manager_android/tags/ndef.dart create mode 100644 lib/src/nfc_manager_android/tags/ndef_formatable.dart create mode 100644 lib/src/nfc_manager_android/tags/nfc_a.dart create mode 100644 lib/src/nfc_manager_android/tags/nfc_b.dart create mode 100644 lib/src/nfc_manager_android/tags/nfc_barcode.dart create mode 100644 lib/src/nfc_manager_android/tags/nfc_f.dart create mode 100644 lib/src/nfc_manager_android/tags/nfc_v.dart create mode 100644 lib/src/nfc_manager_android/tags/tag.dart create mode 100644 lib/src/nfc_manager_ios/nfc_manager.dart create mode 100644 lib/src/nfc_manager_ios/nfc_manager_platform.dart create mode 100644 lib/src/nfc_manager_ios/pigeon.dart create mode 100644 lib/src/nfc_manager_ios/pigeon.g.dart create mode 100644 lib/src/nfc_manager_ios/tags/felica.dart create mode 100644 lib/src/nfc_manager_ios/tags/iso15693.dart create mode 100644 lib/src/nfc_manager_ios/tags/iso7816.dart create mode 100644 lib/src/nfc_manager_ios/tags/mifare.dart create mode 100644 lib/src/nfc_manager_ios/tags/ndef.dart delete mode 100644 lib/src/platform_tags/felica.dart delete mode 100644 lib/src/platform_tags/iso15693.dart delete mode 100644 lib/src/platform_tags/iso7816.dart delete mode 100644 lib/src/platform_tags/iso_dep.dart delete mode 100644 lib/src/platform_tags/mifare.dart delete mode 100644 lib/src/platform_tags/mifare_classic.dart delete mode 100644 lib/src/platform_tags/mifare_ultralight.dart delete mode 100644 lib/src/platform_tags/ndef_formatable.dart delete mode 100644 lib/src/platform_tags/nfc_a.dart delete mode 100644 lib/src/platform_tags/nfc_b.dart delete mode 100644 lib/src/platform_tags/nfc_f.dart delete mode 100644 lib/src/platform_tags/nfc_v.dart delete mode 100644 lib/src/translator.dart create mode 100644 pigeon/android.dart create mode 100644 pigeon/ios.dart create mode 100644 pigeon/pigeon_android.dart create mode 100644 pigeon/pigeon_ios.dart diff --git a/.gitignore b/.gitignore index 96486fd..ac5aa98 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,4 @@ migrate_working_dir/ /pubspec.lock **/doc/api/ .dart_tool/ -.packages build/ diff --git a/.metadata b/.metadata index 044504e..63ffe23 100644 --- a/.metadata +++ b/.metadata @@ -1,11 +1,11 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled. +# This file should be version controlled and should not be manually edited. version: - revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 - channel: stable + revision: "db7ef5bf9f59442b0e200a90587e8fa5e0c6336a" + channel: "stable" project_type: plugin @@ -13,14 +13,14 @@ project_type: plugin migration: platforms: - platform: root - create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 - base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 + create_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a + base_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a - platform: android - create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 - base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 + create_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a + base_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a - platform: ios - create_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 - base_revision: e3c29ec00c9c825c891d75054c63fcc46454dca1 + create_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a + base_revision: db7ef5bf9f59442b0e200a90587e8fa5e0c6336a # User provided section diff --git a/CHANGELOG.md b/CHANGELOG.md index b58d6d2..ed809a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,184 +1 @@ -# 3.2.0 - -* Fix build issues - -# 3.1.1 - -* Upgrade kotlin version. - -# 3.1.0 - -* Fix Null-Safety related issues. The following properties are now nullable. - - * `IsoDep#hiLayerResponse` - * `IsoDep#historicalBytes` - * `Iso7816#historicalBytes` - * `Iso7816#applicationData` - * `MiFare#historicalBytes` - -# 3.0.0+2 - -* Update doc. - -# 3.0.0+1 - -* Flutter format. - -# 3.0.0 - -* Upgrade to null safety. - -# 2.0.3 - -* Fix type conversion errors in `FeliCa#readWithoutEncryption` and `FeliCa#requestServiceV2`. - -# 2.0.2 - -* Fix a bug in calling `FeliCa.sendFeliCaCommand` method. - -# 2.0.1+1 - -* Update README. - -# 2.0.1 - -* Fix an error when initializing plugin for non-NFC Android devices. - -# 2.0.0+2 - -* Update doc. -* Flutter format. - -# 2.0.0+1 - -* Update doc. - -# 2.0.0 - -**Has many breaking changes.** - -* Remove `startNdefSession` and `NdefDiscoveredCallback`. -* Rename `startTagSession` to `startSession`. -* Rename `TagPollingOption` to `NfcPollingOption`. -* Rename `NfcSessionError` to `NfcError`. -* Rename `NfcSessionErrorType` to `NfcErrorType`. -* Rename `TagDiscoveredCallback` to `NfcTagCallback`. -* Rename `NfcSessionErrorCallback` to `NfcErrorCallback`. -* Rename `ISO15693` to `Iso15693`. -* Rename `ISO7816` to `Iso7816`. -* Rename `fromTag` to `from`. (e.g. `MiFare.fromTag(tag)` -> `MiFare.from(tag)`) -* Add `NdefTypeNameFormat` enum. -* Add `NdefFormatable`, `MifareClassic` and `MifareUltralight` classes. -* Add `Ndef#read` method. -* Add command-implementations for `FeliCa` and `Iso15693`. -* Upgrade flutter environment. - -# 1.3.2+4 - -* Update README. - -# 1.3.2+3 - -* Update README. - -# 1.3.2+2 - -* Update README. - -# 1.3.2+1 - -* Update README. - -# 1.3.2 - -* Fix crash on Ndef write and writeLock error. - -# 1.3.1 - -* Fix a bug where the error callback was not called. - -# 1.3.0 - -* Add callback to handle error from session. - -# 1.2.0 - -* Make discovered callback async. - -# 1.1.0+1 - -* Update readme. - -# 1.1.0 - -* Add constants. -* Fix misspelled name. -* Fix xcode build warning. -* Increase the Flutter SDK requirement to ^1.10.0. - -# 1.0.1 - -* Fix error on invoking transceive method. - -# 1.0.0 - -* Add platform-specifc-tag operations. -* Remove `NfcSessionType` enum. -* Migrate to pubspec platforms manifest. -* More consistent naming. - -# 0.5.1 - -* Update flutter project files. -* Additional fix for migration to AndroidX. - -# 0.5.0 - -* Migrate to AndroidX. - -# 0.4.0+2 - -* Fix typo on README - -# 0.4.0+1 - -* Update README - -# 0.4.0 - -* Rename `NfcNdef#cachedNdef` to `NfcNdef#cachedMessage`. -* Add `NfcSessionType` enum. -* Add `NfcTagPollingOption` enum. - -# 0.3.0 - -* Add `NdefRecord#createMimeRecord`. -* Add optional parameters `alertMessageIOS` and `errorMessageIOS` displayed in iOS system UI. -* Fix error on deserializing null message on dart side. - -# 0.2.0 - -* Split `startSession` into `startNdefSession` and `startTagSession`. -* Improve doc. - -# 0.1.1 - -* Fix crash on serializing nil message on ios side. -* Add example project. -* Improve doc. - -# 0.1.0+2 - -* Improve doc. - -# 0.1.0+1 - -* Improve doc. - -# 0.1.0 - -* Add iOS 13 features. - -# 0.0.1 - -* Initial release. +## 4.0.0-dev diff --git a/LICENSE b/LICENSE index 52f7a60..2b420f8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Naoki Okada +Copyright (c) 2019 okadan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e967bae..0a0acb7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # nfc_manager -Flutter plugin for accessing the NFC features on Android and iOS. +A Flutter plugin for accessing the NFC features on Android and iOS. -Note: This plugin depends on `NFCTagReaderSession` (requires iOS 13.0 or later) and `NfcAdapter#enableReaderMode` (requires Android API level 19 or later). +## Requirements + +Android SDK Version >= 19 or iOS >= 13.0. ## Setup @@ -16,60 +18,75 @@ Note: This plugin depends on `NFCTagReaderSession` (requires iOS 13.0 or later) * Add [NFCReaderUsageDescription](https://developer.apple.com/documentation/bundleresources/information_property_list/nfcreaderusagedescription) to your `Info.plist`. -* Add [com.apple.developer.nfc.readersession.felica.systemcodes](https://developer.apple.com/documentation/bundleresources/information_property_list/systemcodes) and [com.apple.developer.nfc.readersession.iso7816.select-identifiers](https://developer.apple.com/documentation/bundleresources/information_property_list/select-identifiers) to your `Info.plist` as needed. +* Add [com.apple.developer.nfc.readersession.iso7816.select-identifiers](https://developer.apple.com/documentation/bundleresources/information_property_list/select-identifiers) to your `Info.plist`. (Optional) -## Usage +* Add [com.apple.developer.nfc.readersession.felica.systemcodes](https://developer.apple.com/documentation/bundleresources/information_property_list/systemcodes) to your `Info.plist`. (Optional but required if you specify the `NfcPollingOptions.iso18092` to the `pollingOptions`) -**Handling Session** +## Minimum Usage ```dart -// Check availability bool isAvailable = await NfcManager.instance.isAvailable(); -// Start Session +if (!isAvailable) { + print("The NFC features may not be supported on this device."); + return; +} + NfcManager.instance.startSession( + pollingOptions: ..., onDiscovered: (NfcTag tag) async { // Do something with an NfcTag instance. + + // Stop the session when the processing is completed. + NfcManager.instance.stopSession(); }, ); - -// Stop Session -NfcManager.instance.stopSession(); ``` -**Handling Platform Tag** +## Handling the NfcTag instance. + +NfcTag is typically not used directly, but only to obtain an instance of a specific tag type. This plugin provides the following tag types: -The following platform-tag-classes are available: +**Android Only** -* Ndef -* FeliCa (iOS only) -* Iso7816 (iOS only) -* Iso15693 (iOS only) -* MiFare (iOS only) -* NfcA (Android only) -* NfcB (Android only) -* NfcF (Android only) -* NfcV (Android only) -* IsoDep (Android only) -* MifareClassic (Android only) -* MifareUtralight (Android only) -* NdefFormatable (Android only) +* `NdefAndroid` +* `NfcAAndroid` +* `NfcBAndroid` +* `NfcFAndroid` +* `NfcVAndroid` +* `IsoDepAndroid` +* `MifareClassicAndroid` +* `MifareUltralightAndroid` +* `NdefFormatableAndroid` +* `NfcBarcodeAndroid` -Obtain an instance by calling the factory constructor `from` on the class. For example: +**iOS Only** + +* `NdefIOS` +* `MiFareIOS` +* `FeliCaIOS` +* `Iso15693IOS` +* `Iso7618IOS` + +**Abstraction between Android and iOS (sub packages)** + +* `Ndef` ([nfc_manager_ndef](https://github.com/okadan/flutter-nfc-manager-ndef)) +* `FeliCa` ([nfc_manager_felica](https://github.com/okadan/flutter-nfc-manager-felica)) +* Add more in the future... + +Use `from(NfcTag)` static method to obtain an instance of a specific tag type. For example, to instantiate the `Ndef`: ```dart +import 'package:nfc_manager_ndef/nfc_manager_ndef.dart'; + Ndef? ndef = Ndef.from(tag); if (ndef == null) { - print('Tag is not compatible with NDEF'); + print("The tag is not compatible with an NDEF."); return; } -// Do something with an Ndef instance +// Do something with an Ndef instance. ``` -Please see the [API Doc](https://pub.dev/documentation/nfc_manager/latest/) for more details. - -## Real-World-App - -See [this repo](https://github.com/okadan/flutter-nfc-manager-app) which is a Real-World-App demonstrates how to use this plugin. +See the [example](#) directory or [Real World App](#) for more details. diff --git a/android/build.gradle b/android/build.gradle index dff31fd..da27898 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,15 +1,15 @@ -group 'io.flutter.plugins.nfc_manager' +group 'dev.flutter.plugins.nfcmanager' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.1.2' + classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -25,7 +25,11 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { - compileSdkVersion 31 + if (project.android.hasProperty("namespace")) { + namespace 'dev.flutter.plugins.nfcmanager' + } + + compileSdkVersion 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -38,9 +42,27 @@ android { sourceSets { main.java.srcDirs += 'src/main/kotlin' + test.java.srcDirs += 'src/test/kotlin' } defaultConfig { - minSdkVersion 16 + minSdkVersion 19 + } + + dependencies { + testImplementation 'org.jetbrains.kotlin:kotlin-test' + testImplementation 'org.mockito:mockito-core:5.0.0' + } + + testOptions { + unitTests.all { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed", "standardOut", "standardError" + outputs.upToDateWhen {false} + showStandardStreams = true + } + } } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index a33fc2e..4728e2e 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="dev.flutter.plugins.nfcmanager"> diff --git a/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPlugin.kt b/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPlugin.kt new file mode 100644 index 0000000..05c1f07 --- /dev/null +++ b/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPlugin.kt @@ -0,0 +1,509 @@ +package dev.flutter.plugins.nfcmanager + +import android.app.Activity +import android.app.PendingIntent +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.nfc.NdefMessage +import android.nfc.NdefRecord +import android.nfc.NfcAdapter +import android.nfc.Tag +import android.nfc.tech.* +import android.os.Build +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.activity.ActivityAware +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding +import java.util.* + +class NfcManagerPlugin: FlutterPlugin, ActivityAware, PigeonHostApi, BroadcastReceiver() { + private lateinit var flutterApi: PigeonFlutterApi + private lateinit var activity: Activity + private var adapter: NfcAdapter? = null + private var cachedTags: MutableMap = mutableMapOf() + private var connectedTech: TagTechnology? = null + + override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + PigeonHostApi.setUp(flutterPluginBinding.binaryMessenger, this) + flutterApi = PigeonFlutterApi(flutterPluginBinding.binaryMessenger) + adapter = NfcAdapter.getDefaultAdapter(flutterPluginBinding.applicationContext) + } + + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { + PigeonHostApi.setUp(binding.binaryMessenger, null) + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + activity = binding.activity + activity.applicationContext.registerReceiver(this, null) + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + activity = binding.activity + } + + override fun onDetachedFromActivityForConfigChanges() { + // noop + } + + override fun onDetachedFromActivity() { + // noop + } + + override fun onReceive(context: Context?, intent: Intent?) { + intent ?: run { return } + if (intent.action != NfcAdapter.ACTION_ADAPTER_STATE_CHANGED) { return } + val state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF) + flutterApi.onAdapterStateChanged(state.toLong()) { /* noop */ } + } + + override fun nfcAdapterIsEnabled(): Boolean { + val adapter = adapter ?: run { throw Exception("TODO") } + return adapter.isEnabled + } + + override fun nfcAdapterIsSecureNfcEnabled(): Boolean { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { throw Exception("TODO") } + val adapter = adapter ?: run { throw Exception("TODO") } + return adapter.isSecureNfcEnabled + } + + override fun nfcAdapterIsSecureNfcSupported(): Boolean { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { throw Exception("TODO") } + val adapter = adapter ?: run { throw Exception("TODO") } + return adapter.isSecureNfcSupported + } + + override fun nfcAdapterEnableReaderMode(flags: List) { + val adapter = adapter ?: run { throw Exception("TODO") } + adapter.enableReaderMode(activity, { onTagDiscovered(it) }, toInt(flags), null) + } + + override fun nfcAdapterDisableReaderMode() { + val adapter = adapter ?: run { throw Exception("TODO") } + adapter.disableReaderMode(activity) + cachedTags.clear() // FIXME: Consider when to remove the tag. + } + + override fun nfcAdapterEnableForegroundDispatch() { + val adapter = adapter ?: run { throw Exception("TODO") } + val intent = Intent(activity.applicationContext, javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) + val pendingIntent = PendingIntent.getActivity(activity.applicationContext, 0, intent, 0) + adapter.enableForegroundDispatch(activity, pendingIntent, null, null) + } + + override fun nfcAdapterDisableForegroundDispatch() { + val adapter = adapter ?: run { throw Exception("TODO") } + adapter.disableForegroundDispatch(activity) + } + + override fun ndefGetNdefMessage(handle: String): PigeonNdefMessage? { + val tech = forceConnect(handle) { Ndef.get(it) } + val message = tech.ndefMessage + return if (message != null) toPigeonNdefMessage(message) else null + } + + override fun ndefWriteNdefMessage(handle: String, message: PigeonNdefMessage) { + val tech = forceConnect(handle) { Ndef.get(it) } + tech.writeNdefMessage(toNdefMessage(message)) + } + + override fun ndefMakeReadOnly(handle: String): Boolean { + val tech = forceConnect(handle) { Ndef.get(it) } + return tech.makeReadOnly() + } + + override fun nfcAGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { NfcA.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun nfcAGetTimeout(handle: String): Long { + val tech = forceConnect(handle) { NfcA.get(it) } + return tech.timeout.toLong() + } + + override fun nfcASetTimeout(handle: String, timeout: Long) { + val tech = forceConnect(handle) { NfcA.get(it) } + tech.timeout = timeout.toInt() + } + + override fun nfcATransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { NfcA.get(it) } + return tech.transceive(bytes) + } + + override fun nfcBGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { NfcB.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun nfcBTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { NfcB.get(it) } + return tech.transceive(bytes) + } + + override fun nfcFGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { NfcF.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun nfcFGetTimeout(handle: String): Long { + val tech = forceConnect(handle) { NfcF.get(it) } + return tech.timeout.toLong() + } + + override fun nfcFSetTimeout(handle: String, timeout: Long) { + val tech = forceConnect(handle) { NfcF.get(it) } + tech.timeout = timeout.toInt() + } + + override fun nfcFTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { NfcF.get(it) } + return tech.transceive(bytes) + } + + override fun nfcVGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { NfcV.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun nfcVTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { NfcV.get(it) } + return tech.transceive(bytes) + } + + override fun isoDepGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { IsoDep.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun isoDepGetTimeout(handle: String): Long { + val tech = forceConnect(handle) { IsoDep.get(it) } + return tech.timeout.toLong() + } + + override fun isoDepSetTimeout(handle: String, timeout: Long) { + val tech = forceConnect(handle) { IsoDep.get(it) } + tech.timeout = timeout.toInt() + } + + override fun isoDepTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { IsoDep.get(it) } + return tech.transceive(bytes) + } + + override fun mifareClassicGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun mifareClassicGetTimeout(handle: String): Long { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.timeout.toLong() + } + + override fun mifareClassicSetTimeout(handle: String, timeout: Long) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.timeout = timeout.toInt() + } + + override fun mifareClassicAuthenticateSectorWithKeyA(handle: String, sectorIndex: Long, key: ByteArray): Boolean { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.authenticateSectorWithKeyA(sectorIndex.toInt(), key) + } + + override fun mifareClassicAuthenticateSectorWithKeyB(handle: String, sectorIndex: Long, key: ByteArray): Boolean { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.authenticateSectorWithKeyB(sectorIndex.toInt(), key) + } + + override fun mifareClassicGetBlockCountInSector(handle: String, sectorIndex: Long): Long { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.getBlockCountInSector(sectorIndex.toInt()).toLong() + } + + override fun mifareClassicBlockToSector(handle: String, blockIndex: Long): Long { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.blockToSector(blockIndex.toInt()).toLong() + } + + override fun mifareClassicSectorToBlock(handle: String, sectorIndex: Long): Long { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.sectorToBlock(sectorIndex.toInt()).toLong() + } + + override fun mifareClassicIncrement(handle: String, blockIndex: Long, value: Long) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.increment(blockIndex.toInt(), value.toInt()) + } + + override fun mifareClassicDecrement(handle: String, blockIndex: Long, value: Long) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.decrement(blockIndex.toInt(), value.toInt()) + } + + override fun mifareClassicRestore(handle: String, blockIndex: Long) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.restore(blockIndex.toInt()) + } + + override fun mifareClassicTransfer(handle: String, blockIndex: Long) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.transfer(blockIndex.toInt()) + } + + override fun mifareClassicReadBlock(handle: String, blockIndex: Long): ByteArray { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.readBlock(blockIndex.toInt()) + } + + override fun mifareClassicWriteBlock(handle: String, blockIndex: Long, data: ByteArray) { + val tech = forceConnect(handle) { MifareClassic.get(it) } + tech.writeBlock(blockIndex.toInt(), data) + } + + override fun mifareClassicTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { MifareClassic.get(it) } + return tech.transceive(bytes) + } + + override fun mifareUltralightGetMaxTransceiveLength(handle: String): Long { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + return tech.maxTransceiveLength.toLong() + } + + override fun mifareUltralightGetTimeout(handle: String): Long { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + return tech.timeout.toLong() + } + + override fun mifareUltralightSetTimeout(handle: String, timeout: Long) { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + tech.timeout = timeout.toInt() + } + + override fun mifareUltralightReadPages(handle: String, pageOffset: Long): ByteArray { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + return tech.readPages(pageOffset.toInt()) + } + + override fun mifareUltralightWritePage(handle: String, pageOffset: Long, data: ByteArray) { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + tech.writePage(pageOffset.toInt(), data) + } + + override fun mifareUltralightTransceive(handle: String, bytes: ByteArray): ByteArray { + val tech = forceConnect(handle) { MifareUltralight.get(it) } + return tech.transceive(bytes) + } + + override fun ndefFormatableFormat(handle: String, firstMessage: PigeonNdefMessage) { + val tech = forceConnect(handle) { NdefFormatable.get(it) } + tech.format(toNdefMessage(firstMessage)) + } + + override fun ndefFormatableFormatReadOnly(handle: String, firstMessage: PigeonNdefMessage) { + val tech = forceConnect(handle) { NdefFormatable.get(it) } + tech.formatReadOnly(toNdefMessage(firstMessage)) + } + + private fun onTagDiscovered(tag: Tag) { + val handle = UUID.randomUUID().toString() + val pigeonTag = toPigeonTag(tag, handle) + cachedTags[handle] = tag + activity.runOnUiThread { flutterApi.onTagDiscovered(pigeonTag) { /* no op */ } } + } + + private fun forceConnect(handle: String, getMethod: (Tag) -> T?): T { + val tag = cachedTags[handle] ?: run { throw Exception("TODO") } + val tech = getMethod(tag) ?: run { throw Exception("TODO") } + val connectedTech = connectedTech ?: run { + tech.connect() + connectedTech = tech + return tech + } + if (connectedTech.tag != tech.tag || connectedTech::class.java.name != tech::class.java.name) { + try { connectedTech.close() } catch (e: Exception) { /* no op */ } + tech.connect() + this.connectedTech = tech + return tech + } + return tech + } +} + +private fun toInt(value: List): Int { + return value.fold(0) { p, e -> p or toInt(e)} +} + +private fun toInt(value: String): Int { + return when (value) { + "nfcA" -> NfcAdapter.FLAG_READER_NFC_A + "nfcB" -> NfcAdapter.FLAG_READER_NFC_B + "nfcBarcode" -> NfcAdapter.FLAG_READER_NFC_BARCODE + "nfcF" -> NfcAdapter.FLAG_READER_NFC_F + "nfcV" -> NfcAdapter.FLAG_READER_NFC_V + "noPlatformSounds" -> NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS + "skipNdefCheck" -> NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK + else -> throw IllegalArgumentException("$value is Unknown") + } +} + +private fun toNdefMessage(value: PigeonNdefMessage): NdefMessage { + return NdefMessage(value.records.map { toNdefRecord(it!!) }.toTypedArray()) +} + +private fun toPigeonNdefMessage(value: NdefMessage): PigeonNdefMessage { + return PigeonNdefMessage( + records = value.records.map { toPigeonNdefRecord(it) } + ) +} + +private fun toNdefRecord(value: PigeonNdefRecord): NdefRecord { + return NdefRecord( + toShort(value.tnf), + value.type, + value.id, + value.payload, + ) +} + +private fun toPigeonNdefRecord(value: NdefRecord): PigeonNdefRecord { + return PigeonNdefRecord( + tnf = toPigeonTypeNameFormat(value.tnf), + type = value.type, + id = value.id, + payload = value.payload, + ) +} + +private fun toPigeonTag(value: Tag, handle: String): PigeonTag { + return PigeonTag( + handle = handle, + id = value.id, + techList = value.techList.toMutableList(), + ndef = Ndef.get(value)?.let { toPigeonNdef(it) }, + nfcA = NfcA.get(value)?.let { toPigeonNfcA(it) }, + nfcB = NfcB.get(value)?.let { toPigeonNfcB(it) }, + nfcF = NfcF.get(value)?.let { toPigeonNfcF(it) }, + nfcV = NfcV.get(value)?.let { toPigeonNfcV(it) }, + isoDep = IsoDep.get(value)?.let { toPigeonIsoDep(it) }, + mifareClassic = MifareClassic.get(value)?.let { toPigeonMifareClassic(it) }, + mifareUltralight = MifareUltralight.get(value)?.let { toPigeonMifareUltralight(it) }, + ndefFormatable = NdefFormatable.get(value)?.let { "" }, + nfcBarcode = NfcBarcode.get(value)?.let { toPigeonNfcBarcode(it) }, + ) +} + +private fun toPigeonNdef(value: Ndef): PigeonNdef { + return PigeonNdef( + type = value.type, + isWritable = value.isWritable, + maxSize = value.maxSize.toLong(), + canMakeReadOnly = value.canMakeReadOnly(), + cachedNdefMessage = value.cachedNdefMessage?.let { toPigeonNdefMessage(it) }, + ) +} + +private fun toPigeonNfcA(value: NfcA): PigeonNfcA { + return PigeonNfcA( + atqa = value.atqa, + sak = value.sak.toLong(), + ) +} + +private fun toPigeonNfcB(value: NfcB): PigeonNfcB { + return PigeonNfcB( + applicationData = value.applicationData, + protocolInfo = value.protocolInfo, + ) +} + +private fun toPigeonNfcF(value: NfcF): PigeonNfcF { + return PigeonNfcF( + manufacturer = value.manufacturer, + systemCode = value.systemCode, + ) +} + +private fun toPigeonNfcV(value: NfcV): PigeonNfcV { + return PigeonNfcV( + dsfId = value.dsfId.toLong(), + responseFlags = value.responseFlags.toLong(), + ) +} + +private fun toPigeonIsoDep(value: IsoDep): PigeonIsoDep { + return PigeonIsoDep( + hiLayerResponse = value.hiLayerResponse, + historicalBytes = value.historicalBytes, + isExtendedLengthApduSupported = value.isExtendedLengthApduSupported, + ) +} + +private fun toPigeonMifareClassic(value: MifareClassic): PigeonMifareClassic { + return PigeonMifareClassic( + type = toPigeonMifareClassicType(value.type), + blockCount = value.blockCount.toLong(), + sectorCount = value.sectorCount.toLong(), + size = value.size.toLong(), + ) +} + +private fun toPigeonMifareUltralight(value: MifareUltralight): PigeonMifareUltralight { + return PigeonMifareUltralight( + type = toPigeonMifareUltralightType(value.type) + ) +} + +private fun toPigeonNfcBarcode(value: NfcBarcode): PigeonNfcBarcode { + return PigeonNfcBarcode( + type = value.type.toLong(), + barcode = value.barcode, + ) +} + +private fun toShort(value: PigeonTypeNameFormat): Short { + return when (value) { + PigeonTypeNameFormat.EMPTY -> NdefRecord.TNF_EMPTY + PigeonTypeNameFormat.WELLKNOWN -> NdefRecord.TNF_WELL_KNOWN + PigeonTypeNameFormat.MEDIA -> NdefRecord.TNF_MIME_MEDIA + PigeonTypeNameFormat.ABSOLUTEURI -> NdefRecord.TNF_ABSOLUTE_URI + PigeonTypeNameFormat.EXTERNAL -> NdefRecord.TNF_EXTERNAL_TYPE + PigeonTypeNameFormat.UNKNOWN -> NdefRecord.TNF_UNKNOWN + PigeonTypeNameFormat.UNCHANGED -> NdefRecord.TNF_UNCHANGED + } +} + +private fun toPigeonTypeNameFormat(value: Short): PigeonTypeNameFormat { + return when (value) { + NdefRecord.TNF_EMPTY -> PigeonTypeNameFormat.EMPTY + NdefRecord.TNF_WELL_KNOWN -> PigeonTypeNameFormat.WELLKNOWN + NdefRecord.TNF_MIME_MEDIA -> PigeonTypeNameFormat.MEDIA + NdefRecord.TNF_ABSOLUTE_URI -> PigeonTypeNameFormat.ABSOLUTEURI + NdefRecord.TNF_EXTERNAL_TYPE -> PigeonTypeNameFormat.EXTERNAL + NdefRecord.TNF_UNKNOWN -> PigeonTypeNameFormat.UNKNOWN + NdefRecord.TNF_UNCHANGED -> PigeonTypeNameFormat.UNCHANGED + else -> error("TODO:") + } +} + +private fun toPigeonMifareClassicType(value: Int): PigeonMifareClassicType { + return when (value) { + MifareClassic.TYPE_CLASSIC -> PigeonMifareClassicType.CLASSIC + MifareClassic.TYPE_PLUS -> PigeonMifareClassicType.PLUS + MifareClassic.TYPE_PRO -> PigeonMifareClassicType.PRO + MifareClassic.TYPE_UNKNOWN -> PigeonMifareClassicType.UNKNOWN + else -> error("TODO:") + } +} + +private fun toPigeonMifareUltralightType(value: Int): PigeonMifareUltralightType { + return when (value) { + MifareUltralight.TYPE_ULTRALIGHT -> PigeonMifareUltralightType.ULTRALIGHT + MifareUltralight.TYPE_ULTRALIGHT_C -> PigeonMifareUltralightType.ULTRALIGHTC + MifareUltralight.TYPE_UNKNOWN -> PigeonMifareUltralightType.UNKNOWN + else -> error("TODO:") + } +} diff --git a/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt b/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt new file mode 100644 index 0000000..9454b3f --- /dev/null +++ b/android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt @@ -0,0 +1,1611 @@ +// Autogenerated from Pigeon (v15.0.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +package dev.flutter.plugins.nfcmanager + +import android.util.Log +import io.flutter.plugin.common.BasicMessageChannel +import io.flutter.plugin.common.BinaryMessenger +import io.flutter.plugin.common.MessageCodec +import io.flutter.plugin.common.StandardMessageCodec +import java.io.ByteArrayOutputStream +import java.nio.ByteBuffer + +private fun wrapResult(result: Any?): List { + return listOf(result) +} + +private fun wrapError(exception: Throwable): List { + if (exception is FlutterError) { + return listOf( + exception.code, + exception.message, + exception.details + ) + } else { + return listOf( + exception.javaClass.simpleName, + exception.toString(), + "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) + ) + } +} + +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + +/** + * Error class for passing custom error details to Flutter via a thrown PlatformException. + * @property code The error code. + * @property message The error message. + * @property details The error details. Must be a datatype supported by the api codec. + */ +class FlutterError ( + val code: String, + override val message: String? = null, + val details: Any? = null +) : Throwable() + +enum class PigeonTypeNameFormat(val raw: Int) { + EMPTY(0), + WELLKNOWN(1), + MEDIA(2), + ABSOLUTEURI(3), + EXTERNAL(4), + UNKNOWN(5), + UNCHANGED(6); + + companion object { + fun ofRaw(raw: Int): PigeonTypeNameFormat? { + return values().firstOrNull { it.raw == raw } + } + } +} + +enum class PigeonMifareClassicType(val raw: Int) { + CLASSIC(0), + PLUS(1), + PRO(2), + UNKNOWN(3); + + companion object { + fun ofRaw(raw: Int): PigeonMifareClassicType? { + return values().firstOrNull { it.raw == raw } + } + } +} + +enum class PigeonMifareUltralightType(val raw: Int) { + ULTRALIGHT(0), + ULTRALIGHTC(1), + UNKNOWN(2); + + companion object { + fun ofRaw(raw: Int): PigeonMifareUltralightType? { + return values().firstOrNull { it.raw == raw } + } + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonTag ( + val handle: String, + val id: ByteArray, + val techList: List, + val ndef: PigeonNdef? = null, + val nfcA: PigeonNfcA? = null, + val nfcB: PigeonNfcB? = null, + val nfcF: PigeonNfcF? = null, + val nfcV: PigeonNfcV? = null, + val isoDep: PigeonIsoDep? = null, + val mifareClassic: PigeonMifareClassic? = null, + val mifareUltralight: PigeonMifareUltralight? = null, + val ndefFormatable: String? = null, + val nfcBarcode: PigeonNfcBarcode? = null + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonTag { + val handle = list[0] as String + val id = list[1] as ByteArray + val techList = list[2] as List + val ndef: PigeonNdef? = (list[3] as List?)?.let { + PigeonNdef.fromList(it) + } + val nfcA: PigeonNfcA? = (list[4] as List?)?.let { + PigeonNfcA.fromList(it) + } + val nfcB: PigeonNfcB? = (list[5] as List?)?.let { + PigeonNfcB.fromList(it) + } + val nfcF: PigeonNfcF? = (list[6] as List?)?.let { + PigeonNfcF.fromList(it) + } + val nfcV: PigeonNfcV? = (list[7] as List?)?.let { + PigeonNfcV.fromList(it) + } + val isoDep: PigeonIsoDep? = (list[8] as List?)?.let { + PigeonIsoDep.fromList(it) + } + val mifareClassic: PigeonMifareClassic? = (list[9] as List?)?.let { + PigeonMifareClassic.fromList(it) + } + val mifareUltralight: PigeonMifareUltralight? = (list[10] as List?)?.let { + PigeonMifareUltralight.fromList(it) + } + val ndefFormatable = list[11] as String? + val nfcBarcode: PigeonNfcBarcode? = (list[12] as List?)?.let { + PigeonNfcBarcode.fromList(it) + } + return PigeonTag(handle, id, techList, ndef, nfcA, nfcB, nfcF, nfcV, isoDep, mifareClassic, mifareUltralight, ndefFormatable, nfcBarcode) + } + } + fun toList(): List { + return listOf( + handle, + id, + techList, + ndef?.toList(), + nfcA?.toList(), + nfcB?.toList(), + nfcF?.toList(), + nfcV?.toList(), + isoDep?.toList(), + mifareClassic?.toList(), + mifareUltralight?.toList(), + ndefFormatable, + nfcBarcode?.toList(), + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNdef ( + val type: String, + val canMakeReadOnly: Boolean, + val isWritable: Boolean, + val maxSize: Long, + val cachedNdefMessage: PigeonNdefMessage? = null + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNdef { + val type = list[0] as String + val canMakeReadOnly = list[1] as Boolean + val isWritable = list[2] as Boolean + val maxSize = list[3].let { if (it is Int) it.toLong() else it as Long } + val cachedNdefMessage: PigeonNdefMessage? = (list[4] as List?)?.let { + PigeonNdefMessage.fromList(it) + } + return PigeonNdef(type, canMakeReadOnly, isWritable, maxSize, cachedNdefMessage) + } + } + fun toList(): List { + return listOf( + type, + canMakeReadOnly, + isWritable, + maxSize, + cachedNdefMessage?.toList(), + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNfcA ( + val atqa: ByteArray, + val sak: Long + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNfcA { + val atqa = list[0] as ByteArray + val sak = list[1].let { if (it is Int) it.toLong() else it as Long } + return PigeonNfcA(atqa, sak) + } + } + fun toList(): List { + return listOf( + atqa, + sak, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNfcB ( + val applicationData: ByteArray, + val protocolInfo: ByteArray + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNfcB { + val applicationData = list[0] as ByteArray + val protocolInfo = list[1] as ByteArray + return PigeonNfcB(applicationData, protocolInfo) + } + } + fun toList(): List { + return listOf( + applicationData, + protocolInfo, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNfcF ( + val manufacturer: ByteArray, + val systemCode: ByteArray + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNfcF { + val manufacturer = list[0] as ByteArray + val systemCode = list[1] as ByteArray + return PigeonNfcF(manufacturer, systemCode) + } + } + fun toList(): List { + return listOf( + manufacturer, + systemCode, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNfcV ( + val dsfId: Long, + val responseFlags: Long + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNfcV { + val dsfId = list[0].let { if (it is Int) it.toLong() else it as Long } + val responseFlags = list[1].let { if (it is Int) it.toLong() else it as Long } + return PigeonNfcV(dsfId, responseFlags) + } + } + fun toList(): List { + return listOf( + dsfId, + responseFlags, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonIsoDep ( + val hiLayerResponse: ByteArray? = null, + val historicalBytes: ByteArray? = null, + val isExtendedLengthApduSupported: Boolean + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonIsoDep { + val hiLayerResponse = list[0] as ByteArray? + val historicalBytes = list[1] as ByteArray? + val isExtendedLengthApduSupported = list[2] as Boolean + return PigeonIsoDep(hiLayerResponse, historicalBytes, isExtendedLengthApduSupported) + } + } + fun toList(): List { + return listOf( + hiLayerResponse, + historicalBytes, + isExtendedLengthApduSupported, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonMifareClassic ( + val type: PigeonMifareClassicType, + val blockCount: Long, + val sectorCount: Long, + val size: Long + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonMifareClassic { + val type = PigeonMifareClassicType.ofRaw(list[0] as Int)!! + val blockCount = list[1].let { if (it is Int) it.toLong() else it as Long } + val sectorCount = list[2].let { if (it is Int) it.toLong() else it as Long } + val size = list[3].let { if (it is Int) it.toLong() else it as Long } + return PigeonMifareClassic(type, blockCount, sectorCount, size) + } + } + fun toList(): List { + return listOf( + type.raw, + blockCount, + sectorCount, + size, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonMifareUltralight ( + val type: PigeonMifareUltralightType + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonMifareUltralight { + val type = PigeonMifareUltralightType.ofRaw(list[0] as Int)!! + return PigeonMifareUltralight(type) + } + } + fun toList(): List { + return listOf( + type.raw, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNfcBarcode ( + val type: Long, + val barcode: ByteArray + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNfcBarcode { + val type = list[0].let { if (it is Int) it.toLong() else it as Long } + val barcode = list[1] as ByteArray + return PigeonNfcBarcode(type, barcode) + } + } + fun toList(): List { + return listOf( + type, + barcode, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNdefMessage ( + val records: List + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNdefMessage { + val records = list[0] as List + return PigeonNdefMessage(records) + } + } + fun toList(): List { + return listOf( + records, + ) + } +} + +/** Generated class from Pigeon that represents data sent in messages. */ +data class PigeonNdefRecord ( + val tnf: PigeonTypeNameFormat, + val type: ByteArray, + val id: ByteArray, + val payload: ByteArray + +) { + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): PigeonNdefRecord { + val tnf = PigeonTypeNameFormat.ofRaw(list[0] as Int)!! + val type = list[1] as ByteArray + val id = list[2] as ByteArray + val payload = list[3] as ByteArray + return PigeonNdefRecord(tnf, type, id, payload) + } + } + fun toList(): List { + return listOf( + tnf.raw, + type, + id, + payload, + ) + } +} +@Suppress("UNCHECKED_CAST") +private object PigeonFlutterApiCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 128.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonIsoDep.fromList(it) + } + } + 129.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonMifareClassic.fromList(it) + } + } + 130.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonMifareUltralight.fromList(it) + } + } + 131.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdef.fromList(it) + } + } + 132.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdefMessage.fromList(it) + } + } + 133.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdefRecord.fromList(it) + } + } + 134.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNfcA.fromList(it) + } + } + 135.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNfcB.fromList(it) + } + } + 136.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNfcBarcode.fromList(it) + } + } + 137.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNfcF.fromList(it) + } + } + 138.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNfcV.fromList(it) + } + } + 139.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonTag.fromList(it) + } + } + else -> super.readValueOfType(type, buffer) + } + } + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is PigeonIsoDep -> { + stream.write(128) + writeValue(stream, value.toList()) + } + is PigeonMifareClassic -> { + stream.write(129) + writeValue(stream, value.toList()) + } + is PigeonMifareUltralight -> { + stream.write(130) + writeValue(stream, value.toList()) + } + is PigeonNdef -> { + stream.write(131) + writeValue(stream, value.toList()) + } + is PigeonNdefMessage -> { + stream.write(132) + writeValue(stream, value.toList()) + } + is PigeonNdefRecord -> { + stream.write(133) + writeValue(stream, value.toList()) + } + is PigeonNfcA -> { + stream.write(134) + writeValue(stream, value.toList()) + } + is PigeonNfcB -> { + stream.write(135) + writeValue(stream, value.toList()) + } + is PigeonNfcBarcode -> { + stream.write(136) + writeValue(stream, value.toList()) + } + is PigeonNfcF -> { + stream.write(137) + writeValue(stream, value.toList()) + } + is PigeonNfcV -> { + stream.write(138) + writeValue(stream, value.toList()) + } + is PigeonTag -> { + stream.write(139) + writeValue(stream, value.toList()) + } + else -> super.writeValue(stream, value) + } + } +} + +/** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ +@Suppress("UNCHECKED_CAST") +class PigeonFlutterApi(private val binaryMessenger: BinaryMessenger) { + companion object { + /** The codec used by PigeonFlutterApi. */ + val codec: MessageCodec by lazy { + PigeonFlutterApiCodec + } + } + fun onTagDiscovered(tagArg: PigeonTag, callback: (Result) -> Unit) { + val channelName = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onTagDiscovered" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(tagArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + fun onAdapterStateChanged(stateArg: Long, callback: (Result) -> Unit) { + val channelName = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onAdapterStateChanged" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(stateArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +@Suppress("UNCHECKED_CAST") +private object PigeonHostApiCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 128.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdefMessage.fromList(it) + } + } + 129.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdefMessage.fromList(it) + } + } + 130.toByte() -> { + return (readValue(buffer) as? List)?.let { + PigeonNdefRecord.fromList(it) + } + } + else -> super.readValueOfType(type, buffer) + } + } + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is PigeonNdefMessage -> { + stream.write(128) + writeValue(stream, value.toList()) + } + is PigeonNdefMessage -> { + stream.write(129) + writeValue(stream, value.toList()) + } + is PigeonNdefRecord -> { + stream.write(130) + writeValue(stream, value.toList()) + } + else -> super.writeValue(stream, value) + } + } +} + +/** Generated interface from Pigeon that represents a handler of messages from Flutter. */ +interface PigeonHostApi { + fun nfcAdapterIsEnabled(): Boolean + fun nfcAdapterIsSecureNfcEnabled(): Boolean + fun nfcAdapterIsSecureNfcSupported(): Boolean + fun nfcAdapterEnableReaderMode(flags: List) + fun nfcAdapterDisableReaderMode() + fun nfcAdapterEnableForegroundDispatch() + fun nfcAdapterDisableForegroundDispatch() + fun ndefGetNdefMessage(handle: String): PigeonNdefMessage? + fun ndefWriteNdefMessage(handle: String, message: PigeonNdefMessage) + fun ndefMakeReadOnly(handle: String): Boolean + fun nfcAGetMaxTransceiveLength(handle: String): Long + fun nfcAGetTimeout(handle: String): Long + fun nfcASetTimeout(handle: String, timeout: Long) + fun nfcATransceive(handle: String, bytes: ByteArray): ByteArray + fun nfcBGetMaxTransceiveLength(handle: String): Long + fun nfcBTransceive(handle: String, bytes: ByteArray): ByteArray + fun nfcFGetMaxTransceiveLength(handle: String): Long + fun nfcFGetTimeout(handle: String): Long + fun nfcFSetTimeout(handle: String, timeout: Long) + fun nfcFTransceive(handle: String, bytes: ByteArray): ByteArray + fun nfcVGetMaxTransceiveLength(handle: String): Long + fun nfcVTransceive(handle: String, bytes: ByteArray): ByteArray + fun isoDepGetMaxTransceiveLength(handle: String): Long + fun isoDepGetTimeout(handle: String): Long + fun isoDepSetTimeout(handle: String, timeout: Long) + fun isoDepTransceive(handle: String, bytes: ByteArray): ByteArray + fun mifareClassicGetMaxTransceiveLength(handle: String): Long + fun mifareClassicGetTimeout(handle: String): Long + fun mifareClassicSetTimeout(handle: String, timeout: Long) + fun mifareClassicBlockToSector(handle: String, blockIndex: Long): Long + fun mifareClassicGetBlockCountInSector(handle: String, sectorIndex: Long): Long + fun mifareClassicSectorToBlock(handle: String, sectorIndex: Long): Long + fun mifareClassicAuthenticateSectorWithKeyA(handle: String, sectorIndex: Long, key: ByteArray): Boolean + fun mifareClassicAuthenticateSectorWithKeyB(handle: String, sectorIndex: Long, key: ByteArray): Boolean + fun mifareClassicIncrement(handle: String, blockIndex: Long, value: Long) + fun mifareClassicDecrement(handle: String, blockIndex: Long, value: Long) + fun mifareClassicReadBlock(handle: String, blockIndex: Long): ByteArray + fun mifareClassicWriteBlock(handle: String, blockIndex: Long, data: ByteArray) + fun mifareClassicRestore(handle: String, blockIndex: Long) + fun mifareClassicTransfer(handle: String, blockIndex: Long) + fun mifareClassicTransceive(handle: String, bytes: ByteArray): ByteArray + fun mifareUltralightGetMaxTransceiveLength(handle: String): Long + fun mifareUltralightGetTimeout(handle: String): Long + fun mifareUltralightSetTimeout(handle: String, timeout: Long) + fun mifareUltralightReadPages(handle: String, pageOffset: Long): ByteArray + fun mifareUltralightWritePage(handle: String, pageOffset: Long, data: ByteArray) + fun mifareUltralightTransceive(handle: String, bytes: ByteArray): ByteArray + fun ndefFormatableFormat(handle: String, firstMessage: PigeonNdefMessage) + fun ndefFormatableFormatReadOnly(handle: String, firstMessage: PigeonNdefMessage) + + companion object { + /** The codec used by PigeonHostApi. */ + val codec: MessageCodec by lazy { + PigeonHostApiCodec + } + /** Sets up an instance of `PigeonHostApi` to handle messages through the `binaryMessenger`. */ + @Suppress("UNCHECKED_CAST") + fun setUp(binaryMessenger: BinaryMessenger, api: PigeonHostApi?) { + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsEnabled", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.nfcAdapterIsEnabled()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsSecureNfcEnabled", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.nfcAdapterIsSecureNfcEnabled()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsSecureNfcSupported", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + wrapped = listOf(api.nfcAdapterIsSecureNfcSupported()) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterEnableReaderMode", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val flagsArg = args[0] as List + var wrapped: List + try { + api.nfcAdapterEnableReaderMode(flagsArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterDisableReaderMode", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + api.nfcAdapterDisableReaderMode() + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterEnableForegroundDispatch", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + api.nfcAdapterEnableForegroundDispatch() + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterDisableForegroundDispatch", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + var wrapped: List + try { + api.nfcAdapterDisableForegroundDispatch() + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefGetNdefMessage", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.ndefGetNdefMessage(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteNdefMessage", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val messageArg = args[1] as PigeonNdefMessage + var wrapped: List + try { + api.ndefWriteNdefMessage(handleArg, messageArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefMakeReadOnly", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.ndefMakeReadOnly(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcAGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAGetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcAGetTimeout(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcASetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val timeoutArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.nfcASetTimeout(handleArg, timeoutArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcATransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.nfcATransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcBGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcBGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcBTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.nfcBTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcFGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFGetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcFGetTimeout(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFSetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val timeoutArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.nfcFSetTimeout(handleArg, timeoutArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.nfcFTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcVGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.nfcVGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcVTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.nfcVTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.isoDepGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepGetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.isoDepGetTimeout(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepSetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val timeoutArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.isoDepSetTimeout(handleArg, timeoutArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.isoDepTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.mifareClassicGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.mifareClassicGetTimeout(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicSetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val timeoutArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareClassicSetTimeout(handleArg, timeoutArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicBlockToSector", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.mifareClassicBlockToSector(handleArg, blockIndexArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetBlockCountInSector", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val sectorIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.mifareClassicGetBlockCountInSector(handleArg, sectorIndexArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicSectorToBlock", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val sectorIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.mifareClassicSectorToBlock(handleArg, sectorIndexArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicAuthenticateSectorWithKeyA", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val sectorIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val keyArg = args[2] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.mifareClassicAuthenticateSectorWithKeyA(handleArg, sectorIndexArg, keyArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicAuthenticateSectorWithKeyB", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val sectorIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val keyArg = args[2] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.mifareClassicAuthenticateSectorWithKeyB(handleArg, sectorIndexArg, keyArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicIncrement", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val valueArg = args[2].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareClassicIncrement(handleArg, blockIndexArg, valueArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicDecrement", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val valueArg = args[2].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareClassicDecrement(handleArg, blockIndexArg, valueArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicReadBlock", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.mifareClassicReadBlock(handleArg, blockIndexArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicWriteBlock", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val dataArg = args[2] as ByteArray + var wrapped: List + try { + api.mifareClassicWriteBlock(handleArg, blockIndexArg, dataArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicRestore", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareClassicRestore(handleArg, blockIndexArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicTransfer", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val blockIndexArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareClassicTransfer(handleArg, blockIndexArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.mifareClassicTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightGetMaxTransceiveLength", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.mifareUltralightGetMaxTransceiveLength(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightGetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + var wrapped: List + try { + wrapped = listOf(api.mifareUltralightGetTimeout(handleArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightSetTimeout", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val timeoutArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + api.mifareUltralightSetTimeout(handleArg, timeoutArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightReadPages", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val pageOffsetArg = args[1].let { if (it is Int) it.toLong() else it as Long } + var wrapped: List + try { + wrapped = listOf(api.mifareUltralightReadPages(handleArg, pageOffsetArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightWritePage", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val pageOffsetArg = args[1].let { if (it is Int) it.toLong() else it as Long } + val dataArg = args[2] as ByteArray + var wrapped: List + try { + api.mifareUltralightWritePage(handleArg, pageOffsetArg, dataArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightTransceive", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val bytesArg = args[1] as ByteArray + var wrapped: List + try { + wrapped = listOf(api.mifareUltralightTransceive(handleArg, bytesArg)) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefFormatableFormat", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val firstMessageArg = args[1] as PigeonNdefMessage + var wrapped: List + try { + api.ndefFormatableFormat(handleArg, firstMessageArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefFormatableFormatReadOnly", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val handleArg = args[0] as String + val firstMessageArg = args[1] as PigeonNdefMessage + var wrapped: List + try { + api.ndefFormatableFormatReadOnly(handleArg, firstMessageArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } +} diff --git a/android/src/main/kotlin/io/flutter/plugins/nfcmanager/NfcManagerPlugin.kt b/android/src/main/kotlin/io/flutter/plugins/nfcmanager/NfcManagerPlugin.kt deleted file mode 100644 index fea8aed..0000000 --- a/android/src/main/kotlin/io/flutter/plugins/nfcmanager/NfcManagerPlugin.kt +++ /dev/null @@ -1,348 +0,0 @@ -package io.flutter.plugins.nfcmanager - -import android.app.Activity -import android.nfc.NfcAdapter -import android.nfc.Tag -import android.nfc.tech.IsoDep -import android.nfc.tech.MifareClassic -import android.nfc.tech.MifareUltralight -import android.nfc.tech.Ndef -import android.nfc.tech.NdefFormatable -import android.nfc.tech.NfcA -import android.nfc.tech.NfcB -import android.nfc.tech.NfcF -import android.nfc.tech.NfcV -import android.nfc.tech.TagTechnology -import android.os.Build - -import io.flutter.embedding.engine.plugins.FlutterPlugin -import io.flutter.embedding.engine.plugins.activity.ActivityAware -import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding -import io.flutter.plugin.common.MethodCall -import io.flutter.plugin.common.MethodChannel -import io.flutter.plugin.common.MethodChannel.MethodCallHandler -import io.flutter.plugin.common.MethodChannel.Result -import java.io.IOException -import java.lang.Exception -import java.util.* - -class NfcManagerPlugin: FlutterPlugin, MethodCallHandler, ActivityAware { - private lateinit var channel : MethodChannel - private lateinit var activity: Activity - private lateinit var tags: MutableMap - private var adapter: NfcAdapter? = null - private var connectedTech: TagTechnology? = null - - override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { - channel = MethodChannel(binding.binaryMessenger, "plugins.flutter.io/nfc_manager") - channel.setMethodCallHandler(this) - adapter = NfcAdapter.getDefaultAdapter(binding.applicationContext) - tags = mutableMapOf() - } - - override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { - channel.setMethodCallHandler(null) - } - - override fun onAttachedToActivity(binding: ActivityPluginBinding) { - activity = binding.activity - } - - override fun onDetachedFromActivity() { - // no op - } - - override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { - activity = binding.activity - } - - override fun onDetachedFromActivityForConfigChanges() { - // no op - } - - override fun onMethodCall(call: MethodCall, result: Result) { - when (call.method) { - "Nfc#isAvailable" -> handleNfcIsAvailable(call, result) - "Nfc#startSession" -> handleNfcStartSession(call, result) - "Nfc#stopSession" -> handleNfcStopSession(call, result) - "Nfc#disposeTag" -> handleNfcDisposeTag(call, result) - "Ndef#read" -> handleNdefRead(call, result) - "Ndef#write" -> handleNdefWrite(call, result) - "Ndef#writeLock" -> handleNdefWriteLock(call, result) - "NfcA#transceive" -> handleNfcATransceive(call, result) - "NfcB#transceive" -> handleNfcBTransceive(call, result) - "NfcF#transceive" -> handleNfcFTransceive(call, result) - "NfcV#transceive" -> handleNfcVTransceive(call, result) - "IsoDep#transceive" -> handleIsoDepTransceive(call, result) - "MifareClassic#authenticateSectorWithKeyA" -> handleMifareClassicAuthenticateSectorWithKeyA(call, result) - "MifareClassic#authenticateSectorWithKeyB" -> handleMifareClassicAuthenticateSectorWithKeyB(call, result) - "MifareClassic#increment" -> handleMifareClassicIncrement(call, result) - "MifareClassic#decrement" -> handleMifareClassicDecrement(call, result) - "MifareClassic#readBlock" -> handleMifareClassicReadBlock(call, result) - "MifareClassic#writeBlock" -> handleMifareClassicWriteBlock(call, result) - "MifareClassic#restore" -> handleMifareClassicRestore(call, result) - "MifareClassic#transfer" -> handleMifareClassicTransfer(call, result) - "MifareClassic#transceive" -> handleMifareClassicTransceive(call, result) - "MifareUltralight#readPages" -> handleMifareUltralightReadPages(call, result) - "MifareUltralight#writePage" -> handleMifareUltralightWritePage(call, result) - "MifareUltralight#transceive" -> handleMifareUltralightTransceive(call, result) - "NdefFormatable#format" -> handleNdefFormatableFormat(call, result) - "NdefFormatable#formatReadOnly" -> handleNdefFormatableFormatReadOnly(call, result) - else -> result.notImplemented() - } - } - - private fun handleNfcIsAvailable(call: MethodCall, result: Result) { - result.success(adapter?.isEnabled == true) - } - - private fun handleNfcStartSession(call: MethodCall, result: Result) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - result.error("unavailable", "Requires API level 19.", null) - } else { - val adapter = adapter ?: run { - result.error("unavailable", "NFC is not available for device.", null) - return - } - adapter.enableReaderMode(activity, { - val handle = UUID.randomUUID().toString() - tags[handle] = it - activity.runOnUiThread { channel.invokeMethod("onDiscovered", getTagMap(it).toMutableMap().apply { put("handle", handle) }) } - }, getFlags(call.argument>("pollingOptions")!!), null) - result.success(null) - } - } - - private fun handleNfcStopSession(call: MethodCall, result: Result) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - result.error("unavailable", "Requires API level 19.", null) - } else { - val adapter = adapter ?: run { - result.error("unavailable", "NFC is not available for device.", null) - return - } - adapter.disableReaderMode(activity) - result.success(null) - } - } - - private fun handleNfcDisposeTag(call: MethodCall, result: Result) { - val tag = tags.remove(call.argument("handle")!!) ?: run { - result.success(null) - return - } - - val tech = connectedTech ?: run { - result.success(null) - return - } - - if (tech.tag == tag && tech.isConnected) - try { tech.close() } catch (e: IOException) { /* no op */ } - - connectedTech = null - - result.success(null) - } - - private fun handleNdefRead(call: MethodCall, result: Result) { - tagHandler(call, result, { Ndef.get(it) }) { - val message = it.ndefMessage - result.success(if (message == null) null else getNdefMessageMap(message)) - } - } - - private fun handleNdefWrite(call: MethodCall, result: Result) { - tagHandler(call, result, { Ndef.get(it) }) { - val message = getNdefMessage(call.argument>("message")!!) - it.writeNdefMessage(message) - result.success(null) - } - } - - private fun handleNdefWriteLock(call: MethodCall, result: Result) { - tagHandler(call, result, { Ndef.get(it) }) { - it.makeReadOnly() - result.success(null) - } - } - - private fun handleNfcATransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { NfcA.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleNfcBTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { NfcB.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleNfcFTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { NfcF.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleNfcVTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { NfcV.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleIsoDepTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { IsoDep.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleMifareClassicAuthenticateSectorWithKeyA(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val sectorIndex = call.argument("sectorIndex")!! - val key = call.argument("key")!! - result.success(it.authenticateSectorWithKeyA(sectorIndex, key)) - } - } - - private fun handleMifareClassicAuthenticateSectorWithKeyB(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val sectorIndex = call.argument("sectorIndex")!! - val key = call.argument("key")!! - result.success(it.authenticateSectorWithKeyB(sectorIndex, key)) - } - } - - private fun handleMifareClassicIncrement(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - val value = call.argument("value")!! - it.increment(blockIndex, value) - result.success(null) - } - } - - private fun handleMifareClassicDecrement(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - val value = call.argument("value")!! - it.decrement(blockIndex, value) - result.success(null) - } - } - - private fun handleMifareClassicReadBlock(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - result.success(it.readBlock(blockIndex)) - } - } - - private fun handleMifareClassicWriteBlock(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - val data = call.argument("data")!! - it.writeBlock(blockIndex, data) - result.success(null) - } - } - - private fun handleMifareClassicRestore(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - it.restore(blockIndex) - result.success(null) - } - } - - private fun handleMifareClassicTransfer(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val blockIndex = call.argument("blockIndex")!! - it.transfer(blockIndex) - result.success(null) - } - } - - private fun handleMifareClassicTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareClassic.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleMifareUltralightReadPages(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareUltralight.get(it) }) { - val pageOffset = call.argument("pageOffset")!! - result.success(it.readPages(pageOffset)) - } - } - - private fun handleMifareUltralightWritePage(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareUltralight.get(it) }) { - val pageOffset = call.argument("pageOffset")!! - val data = call.argument("data")!! - it.writePage(pageOffset, data) - result.success(null) - } - } - - private fun handleMifareUltralightTransceive(call: MethodCall, result: Result) { - tagHandler(call, result, { MifareUltralight.get(it) }) { - val data = call.argument("data")!! - result.success(it.transceive(data)) - } - } - - private fun handleNdefFormatableFormat(call: MethodCall, result: Result) { - tagHandler(call, result, { NdefFormatable.get(it) }) { - val firstMessage = getNdefMessage(call.argument>("firstMessage")!!) - it.format(firstMessage) - result.success(null) - } - } - - private fun handleNdefFormatableFormatReadOnly(call: MethodCall, result: Result) { - tagHandler(call, result, { NdefFormatable.get(it) }) { - val firstMessage = getNdefMessage(call.argument>("firstMessage")!!) - it.formatReadOnly(firstMessage) - result.success(null) - } - } - - private fun tagHandler(call: MethodCall, result: Result, getMethod: (Tag) -> T?, callback: (T) -> Unit) { - val tag = tags[call.argument("handle")!!] ?: run { - result.error("invalid_parameter", "Tag is not found", null) - return - } - - val tech = getMethod(tag) ?: run { - result.error("invalid_parameter", "Tech is not supported" , null) - return - } - - try { - forceConnect(tech) - callback(tech) - } catch (e: Exception) { - result.error("io_exception", e.localizedMessage, null) - } - } - - @Throws(IOException::class) - private fun forceConnect(tech: TagTechnology) { - connectedTech?.let { - if (it.tag == tech.tag && it::class.java.name == tech::class.java.name) return - try { tech.close() } catch (e: IOException) { /* no op */ } - tech.connect() - connectedTech = tech - } ?: run { - tech.connect() - connectedTech = tech - } - } -} diff --git a/android/src/main/kotlin/io/flutter/plugins/nfcmanager/Translator.kt b/android/src/main/kotlin/io/flutter/plugins/nfcmanager/Translator.kt deleted file mode 100644 index ec27a26..0000000 --- a/android/src/main/kotlin/io/flutter/plugins/nfcmanager/Translator.kt +++ /dev/null @@ -1,150 +0,0 @@ -package io.flutter.plugins.nfcmanager - -import android.nfc.NdefMessage -import android.nfc.NdefRecord -import android.nfc.NfcAdapter -import android.nfc.Tag -import android.nfc.tech.IsoDep -import android.nfc.tech.MifareClassic -import android.nfc.tech.MifareUltralight -import android.nfc.tech.Ndef -import android.nfc.tech.NfcA -import android.nfc.tech.NfcB -import android.nfc.tech.NfcF -import android.nfc.tech.NfcV -import android.os.Build -import androidx.annotation.RequiresApi -import java.util.* - -@RequiresApi(Build.VERSION_CODES.KITKAT) -fun getFlags(options: List = listOf()): Int { - var flags = 0 - - if (options.contains("iso14443")) { - flags = flags or NfcAdapter.FLAG_READER_NFC_A or NfcAdapter.FLAG_READER_NFC_B - } - - if (options.contains("iso15693")) { - flags = flags or NfcAdapter.FLAG_READER_NFC_V - } - - if (options.contains("iso18092")) { - flags = flags or NfcAdapter.FLAG_READER_NFC_F - } - - return flags -} - -fun getTagMap(arg: Tag): Map { - val data = mutableMapOf() - - arg.techList.forEach { tech -> - // normalize tech string (e.g. "android.nfc.tech.NfcA" => "nfca" - data[tech.toLowerCase(Locale.ROOT).split(".").last()] = when (tech) { - NfcA::class.java.name -> NfcA.get(arg).let { - mapOf( - "identifier" to arg.id, - "atqa" to it.atqa, - "maxTransceiveLength" to it.maxTransceiveLength, - "sak" to it.sak, - "timeout" to it.timeout - ) - } - NfcB::class.java.name -> NfcB.get(arg).let { - mapOf( - "identifier" to arg.id, - "applicationData" to it.applicationData, - "maxTransceiveLength" to it.maxTransceiveLength, - "protocolInfo" to it.protocolInfo - ) - } - NfcF::class.java.name -> NfcF.get(arg).let { - mapOf( - "identifier" to arg.id, - "manufacturer" to it.manufacturer, - "maxTransceiveLength" to it.maxTransceiveLength, - "systemCode" to it.systemCode, - "timeout" to it.timeout - ) - } - NfcV::class.java.name -> NfcV.get(arg).let { - mapOf( - "identifier" to arg.id, - "dsfId" to it.dsfId, - "responseFlags" to it.responseFlags, - "maxTransceiveLength" to it.maxTransceiveLength - ) - } - IsoDep::class.java.name -> IsoDep.get(arg).let { - mapOf( - "identifier" to arg.id, - "hiLayerResponse" to it.hiLayerResponse, - "historicalBytes" to it.historicalBytes, - "isExtendedLengthApduSupported" to it.isExtendedLengthApduSupported, - "maxTransceiveLength" to it.maxTransceiveLength, - "timeout" to it.timeout - ) - } - MifareClassic::class.java.name -> MifareClassic.get(arg).let { - mapOf( - "identifier" to arg.id, - "blockCount" to it.blockCount, - "maxTransceiveLength" to it.maxTransceiveLength, - "sectorCount" to it.sectorCount, - "size" to it.size, - "timeout" to it.timeout, - "type" to it.type - ) - } - MifareUltralight::class.java.name -> MifareUltralight.get(arg).let { - mapOf( - "identifier" to arg.id, - "maxTransceiveLength" to it.maxTransceiveLength, - "timeout" to it.timeout, - "type" to it.type - ) - } - Ndef::class.java.name -> Ndef.get(arg).let { - mapOf( - "identifier" to arg.id, - "isWritable" to it.isWritable, - "maxSize" to it.maxSize, - "canMakeReadOnly" to it.canMakeReadOnly(), - "cachedMessage" to if (it.cachedNdefMessage == null) null else getNdefMessageMap(it.cachedNdefMessage), - "type" to it.type - ) - } - // NdefFormatable or NfcBarcode - else -> mapOf( - "identifier" to arg.id - ) - } - } - - return data -} - -fun getNdefMessage(arg: Map): NdefMessage { - val records = (arg["records"] as List<*>).filterIsInstance>() - return NdefMessage(records.map { - NdefRecord( - (it["typeNameFormat"] as Int).toShort(), - it["type"] as ByteArray, - it["identifier"] as? ByteArray, - it["payload"] as ByteArray - ) - }.toTypedArray()) -} - -fun getNdefMessageMap(arg: NdefMessage): Map { - return mapOf( - "records" to arg.records.map { - mapOf( - "typeNameFormat" to it.tnf, - "type" to it.type, - "identifier" to it.id, - "payload" to it.payload - ) - }.toList() - ) -} diff --git a/android/src/test/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPluginTest.kt b/android/src/test/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPluginTest.kt new file mode 100644 index 0000000..7a34aca --- /dev/null +++ b/android/src/test/kotlin/dev/flutter/plugins/nfcmanager/NfcManagerPluginTest.kt @@ -0,0 +1,11 @@ +package dev.flutter.plugins.nfcmanager + +/* + * This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation. + * + * Once you have built the plugin's example app, you can run these tests from the command + * line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or + * you can run them directly from IDEs that support JUnit such as Android Studio. + */ + +internal class NfcManagerPluginTest {} diff --git a/example/.gitignore b/example/.gitignore index 24476c5..29a3a50 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -27,7 +27,6 @@ migrate_working_dir/ .dart_tool/ .flutter-plugins .flutter-plugins-dependencies -.packages .pub-cache/ .pub/ /build/ diff --git a/example/README.md b/example/README.md index d3cf72b..57145f0 100644 --- a/example/README.md +++ b/example/README.md @@ -1,3 +1,16 @@ # nfc_manager_example Demonstrates how to use the nfc_manager plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index e689118..b0a03f3 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,11 +22,8 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { + namespace "dev.flutter.plugins.nfcmanagerexample" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -44,9 +42,9 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "io.flutter.plugins.nfcmanagerexample" + applicationId "dev.flutter.plugins.nfcmanagerexample" // You can update the following values to match your application needs. - // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() @@ -66,6 +64,4 @@ flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +dependencies {} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index c45f5dc..399f698 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,4 @@ - + @@ -14,13 +16,14 @@ - + - + + diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 05fdf52..aa10bda 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -6,14 +6,14 @@ CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + nfc_manager_example CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 - CFBundleName - nfc_manager_example CFBundlePackageType APPL CFBundleShortVersionString @@ -43,13 +43,5 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIViewControllerBasedStatusBarAppearance - - com.apple.developer.nfc.readersession.felica.systemcodes - - 0000 - - NFCReaderUsageDescription - Read NFC Tags diff --git a/example/ios/Runner/Runner.entitlements b/example/ios/Runner/Runner.entitlements deleted file mode 100644 index 2bb4dee..0000000 --- a/example/ios/Runner/Runner.entitlements +++ /dev/null @@ -1,10 +0,0 @@ - - - - - com.apple.developer.nfc.readersession.formats - - TAG - - - diff --git a/example/ios/RunnerTests/RunnerTests.swift b/example/ios/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..9ff80e2 --- /dev/null +++ b/example/ios/RunnerTests/RunnerTests.swift @@ -0,0 +1,9 @@ +import XCTest + +@testable import nfc_manager + +// This demonstrates a simple unit test of the Swift portion of this plugin's implementation. +// +// See https://developer.apple.com/documentation/xctest for more information about using XCTest. + +class RunnerTests: XCTestCase {} diff --git a/example/lib/main.dart b/example/lib/main.dart index ab30f5b..a10e4e0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,133 +1,2 @@ -import 'dart:typed_data'; - -import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; - -void main() { - WidgetsFlutterBinding.ensureInitialized(); - runApp(MyApp()); -} - -class MyApp extends StatefulWidget { - @override - State createState() => MyAppState(); -} - -class MyAppState extends State { - ValueNotifier result = ValueNotifier(null); - - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: Text('NfcManager Plugin Example')), - body: SafeArea( - child: FutureBuilder( - future: NfcManager.instance.isAvailable(), - builder: (context, ss) => ss.data != true - ? Center(child: Text('NfcManager.isAvailable(): ${ss.data}')) - : Flex( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - direction: Axis.vertical, - children: [ - Flexible( - flex: 2, - child: Container( - margin: EdgeInsets.all(4), - constraints: BoxConstraints.expand(), - decoration: BoxDecoration(border: Border.all()), - child: SingleChildScrollView( - child: ValueListenableBuilder( - valueListenable: result, - builder: (context, value, _) => - Text('${value ?? ''}'), - ), - ), - ), - ), - Flexible( - flex: 3, - child: GridView.count( - padding: EdgeInsets.all(4), - crossAxisCount: 2, - childAspectRatio: 4, - crossAxisSpacing: 4, - mainAxisSpacing: 4, - children: [ - ElevatedButton( - child: Text('Tag Read'), onPressed: _tagRead), - ElevatedButton( - child: Text('Ndef Write'), - onPressed: _ndefWrite), - ElevatedButton( - child: Text('Ndef Write Lock'), - onPressed: _ndefWriteLock), - ], - ), - ), - ], - ), - ), - ), - ), - ); - } - - void _tagRead() { - NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { - result.value = tag.data; - NfcManager.instance.stopSession(); - }); - } - - void _ndefWrite() { - NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { - var ndef = Ndef.from(tag); - if (ndef == null || !ndef.isWritable) { - result.value = 'Tag is not ndef writable'; - NfcManager.instance.stopSession(errorMessage: result.value); - return; - } - - NdefMessage message = NdefMessage([ - NdefRecord.createText('Hello World!'), - NdefRecord.createUri(Uri.parse('https://flutter.dev')), - NdefRecord.createMime( - 'text/plain', Uint8List.fromList('Hello'.codeUnits)), - NdefRecord.createExternal( - 'com.example', 'mytype', Uint8List.fromList('mydata'.codeUnits)), - ]); - - try { - await ndef.write(message); - result.value = 'Success to "Ndef Write"'; - NfcManager.instance.stopSession(); - } catch (e) { - result.value = e; - NfcManager.instance.stopSession(errorMessage: result.value.toString()); - return; - } - }); - } - - void _ndefWriteLock() { - NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { - var ndef = Ndef.from(tag); - if (ndef == null) { - result.value = 'Tag is not ndef'; - NfcManager.instance.stopSession(errorMessage: result.value.toString()); - return; - } - - try { - await ndef.writeLock(); - result.value = 'Success to "Ndef Write Lock"'; - NfcManager.instance.stopSession(); - } catch (e) { - result.value = e; - NfcManager.instance.stopSession(errorMessage: result.value.toString()); - return; - } - }); - } -} +// TODO: add example +void main() {} diff --git a/example/pubspec.lock b/example/pubspec.lock index fac14c4..86aa08a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,42 +5,48 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted version: "1.3.1" flutter: @@ -57,37 +63,50 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.10.0" + ndef_record: + dependency: transitive + description: + path: "." + ref: HEAD + resolved-ref: a105b7cb24ca429d6eb4b7582c496a178e54da65 + url: "https://github.com/okadan/dart-ndef-record" + source: git + version: "1.0.0-dev" nfc_manager: dependency: "direct main" description: path: ".." relative: true source: path - version: "3.2.0" + version: "4.0.0-dev" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -97,51 +116,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + url: "https://pub.dev" + source: hosted + version: "0.3.0" sdks: - dart: ">=2.18.1 <3.0.0" - flutter: ">=2.5.0" + dart: ">=3.2.3 <4.0.0" + flutter: ">=3.3.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a31d2f8..af3d371 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,9 +1,9 @@ name: nfc_manager_example -description: Demonstrates how to use the nfc_manager plugin. +description: "Demonstrates how to use the nfc_manager plugin." publish_to: 'none' environment: - sdk: '>=2.18.1 <3.0.0' + sdk: '>=3.2.0 <4.0.0' dependencies: flutter: diff --git a/ios/Classes/NfcManagerPlugin.h b/ios/Classes/NfcManagerPlugin.h deleted file mode 100644 index d2587cd..0000000 --- a/ios/Classes/NfcManagerPlugin.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface NfcManagerPlugin : NSObject -@end diff --git a/ios/Classes/NfcManagerPlugin.m b/ios/Classes/NfcManagerPlugin.m deleted file mode 100644 index cc6c948..0000000 --- a/ios/Classes/NfcManagerPlugin.m +++ /dev/null @@ -1,15 +0,0 @@ -#import "NfcManagerPlugin.h" -#if __has_include() -#import -#else -// Support project import fallback if the generated compatibility header -// is not copied when this plugin is created as a library. -// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816 -#import "nfc_manager-Swift.h" -#endif - -@implementation NfcManagerPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftNfcManagerPlugin registerWithRegistrar:registrar]; -} -@end diff --git a/ios/Classes/NfcManagerPlugin.swift b/ios/Classes/NfcManagerPlugin.swift new file mode 100644 index 0000000..e994ac7 --- /dev/null +++ b/ios/Classes/NfcManagerPlugin.swift @@ -0,0 +1,802 @@ +import CoreNFC +import Flutter + +public class NfcManagerPlugin: NSObject, FlutterPlugin, PigeonHostApi { + private let flutterApi: PigeonFlutterApi + + private var _tagSession: Any? + @available(iOS 13.0, *) + private var tagSession: NFCTagReaderSession? { + get { return _tagSession as? NFCTagReaderSession } + set { _tagSession = newValue } + } + + private var _vasSession: Any? + @available(iOS 13.0, *) + private var vasSession: NFCVASReaderSession? { + get { return _vasSession as? NFCVASReaderSession } + set { _vasSession = newValue } + } + + private var _cachedTags: Any? + @available(iOS 13.0, *) + private var cachedTags: [String : NFCNDEFTag] { + get { return _cachedTags as? [String : NFCNDEFTag] ?? [:] } + set { _cachedTags = newValue } + } + + private var shouldInvalidateSessionAfterFirstRead: Bool = true + + public static func register(with registrar: FlutterPluginRegistrar) { + PigeonHostApiSetup.setUp(binaryMessenger: registrar.messenger(), api: NfcManagerPlugin(binaryMessenger: registrar.messenger())) + } + + private init(binaryMessenger: FlutterBinaryMessenger) { + flutterApi = PigeonFlutterApi(binaryMessenger: binaryMessenger) + } + + func tagReaderSessionReadingAvailable() throws -> Bool { + guard #available(iOS 13.0, *) else { throw NSError() } + return NFCTagReaderSession.readingAvailable + } + + func tagReaderSessionBegin(pollingOptions: [String], alertMessage: String?, invalidateAfterFirstRead: Bool) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + if tagSession != nil { throw NSError() } + tagSession = NFCTagReaderSession(pollingOption: convert(pollingOptions), delegate: self) + if let alertMessage = alertMessage { tagSession?.alertMessage = alertMessage } + shouldInvalidateSessionAfterFirstRead = invalidateAfterFirstRead + tagSession?.begin() + } + + func tagReaderSessionInvalidate(alertMessage: String?, errorMessage: String?) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + guard let tagSession = tagSession else { throw NSError() } + if let alertMessage = alertMessage { tagSession.alertMessage = alertMessage } + if let errorMessage = errorMessage { tagSession.invalidate(errorMessage: errorMessage) } else { tagSession.invalidate() } + self.tagSession = nil + cachedTags.removeAll() // FIXME: Consider when to remove the tag. + } + + func tagReaderSessionRestartPolling() throws { + guard #available(iOS 13.0, *) else { throw NSError() } + guard let tagSession = tagSession else { throw NSError() } + tagSession.restartPolling() + } + + func tagReaderSessionSetAlertMessage(alertMessage: String) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + guard let tagSession = tagSession else { throw NSError() } + tagSession.alertMessage = alertMessage + } + + func vasReaderSessionReadingAvailable() throws -> Bool { + guard #available(iOS 13.0, *) else { throw NSError() } + return NFCVASReaderSession.readingAvailable + } + + func vasReaderSessionBegin(configurations: [PigeonNfcVasCommandConfiguration], alertMessage: String?) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + if vasSession != nil { throw NSError() } + vasSession = NFCVASReaderSession(vasCommandConfigurations: configurations.map { convert($0) }, delegate: self, queue: nil) + if let alertMessage = alertMessage { vasSession?.alertMessage = alertMessage } + vasSession?.begin() + } + + func vasReaderSessionInvalidate(alertMessage: String?, errorMessage: String?) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + guard let vasSession = vasSession else { throw NSError() } + if let alertMessage = alertMessage { vasSession.alertMessage = alertMessage } + if let errorMessage = errorMessage { vasSession.invalidate(errorMessage: errorMessage) } else { vasSession.invalidate() } + self.vasSession = nil + } + + func vasReaderSessionSetAlertMessage(alertMessage: String) throws { + guard #available(iOS 13.0, *) else { throw NSError() } + guard let vasSession = vasSession else { throw NSError() } + vasSession.alertMessage = alertMessage + } + + func ndefQueryNDEFStatus(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] else { completion(.failure(NSError())); return } + tag.queryNDEFStatus { status, capacity, error in + if let error = error { completion(.failure(error)); return } + } + } + + func ndefReadNDEF(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] else { completion(.failure(NSError())); return } + tag.readNDEF { message, error in + if let error = error { completion(.failure(error)); return } + guard let message = message else { completion(.success(nil)); return } + completion(.success(convert(message))) + } + } + + func ndefWriteNDEF(handle: String, message: PigeonNdefMessage, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] else { completion(.failure(NSError())); return } + tag.writeNDEF(convert(message)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func ndefWriteLock(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] else { completion(.failure(NSError())); return } + tag.writeLock { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func feliCaPolling(handle: String, systemCode: FlutterStandardTypedData, requestCode: PigeonFeliCaPollingRequestCode, timeSlot: PigeonFeliCaPollingTimeSlot, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.polling(systemCode: systemCode.data, requestCode: convert(requestCode), timeSlot: convert(timeSlot)) { manufacturerParameter, requestData, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaPollingResponse( + manufacturerParameter: FlutterStandardTypedData(bytes: manufacturerParameter), + requestData: FlutterStandardTypedData(bytes: requestData) + ))) + } + } + + func feliCaRequestService(handle: String, nodeCodeList: [FlutterStandardTypedData], completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.requestService(nodeCodeList: nodeCodeList.map { $0.data }) { nodeCodeList, error in + if let error = error { completion(.failure(error)); return } + completion(.success(nodeCodeList.map { FlutterStandardTypedData(bytes: $0) })) + } + } + + func feliCaRequestResponse(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.requestResponse { mode, error in + if let error = error { completion(.failure(error)); return } + completion(.success(Int64(mode))) + } + } + + func feliCaReadWithoutEncryption(handle: String, serviceCodeList: [FlutterStandardTypedData], blockList: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.readWithoutEncryption(serviceCodeList: serviceCodeList.map { $0.data }, blockList: blockList.map { $0.data }) { statusFlag1, statusFlag2, blockData, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaReadWithoutEncryptionResponse( + statusFlag1: Int64(statusFlag1), + statusFlag2: Int64(statusFlag2), + blockData: blockData.map { FlutterStandardTypedData(bytes: $0) } + ))) + } + } + + func feliCaWriteWithoutEncryption(handle: String, serviceCodeList: [FlutterStandardTypedData], blockList: [FlutterStandardTypedData], blockData: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.writeWithoutEncryption(serviceCodeList: serviceCodeList.map { $0.data }, blockList: blockList.map { $0.data }, blockData: blockData.map { $0.data }) { statusFlag1, statusFlag2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaStatusFlag( + statusFlag1: Int64(statusFlag1), + statusFlag2: Int64(statusFlag2) + ))) + } + } + + func feliCaRequestSystemCode(handle: String, completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.requestSystemCode() { systemCodeList, error in + if let error = error { completion(.failure(error)); return } + completion(.success(systemCodeList.map { FlutterStandardTypedData(bytes: $0) })) + } + } + + func feliCaRequestServiceV2(handle: String, nodeCodeList: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.requestServiceV2(nodeCodeList: nodeCodeList.map { $0.data }) { statusFlag1, statusFlag2, encryptionIdentifier, nodeKeyVersionListAes, nodeKeyVersionListDes, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaRequestServiceV2Response( + statusFlag1: Int64(statusFlag1), + statusFlag2: Int64(statusFlag2), + encryptionIdentifier: Int64(encryptionIdentifier.rawValue), + nodeKeyVersionListAES: nodeKeyVersionListAes.map { FlutterStandardTypedData(bytes: $0) }, + nodeKeyVersionListDES: nodeKeyVersionListDes.map { FlutterStandardTypedData(bytes: $0) } + ))) + } + } + + func feliCaRequestSpecificationVersion(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.requestSpecificationVersion() { statusFlag1, statusFlag2, basicVersion, optionVersion, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaRequestSpecificationVersionResponse( + statusFlag1: Int64(statusFlag1), + statusFlag2: Int64(statusFlag2), + basicVersion: FlutterStandardTypedData(bytes: basicVersion), + optionVersion: FlutterStandardTypedData(bytes: optionVersion) + ))) + } + } + + func feliCaResetMode(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.resetMode() { statusFlag1, statusFlag2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonFeliCaStatusFlag( + statusFlag1: Int64(statusFlag1), + statusFlag2: Int64(statusFlag2) + ))) + } + } + + func feliCaSendFeliCaCommand(handle: String, commandPacket: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCFeliCaTag else { completion(.failure(NSError())); return } + tag.sendFeliCaCommand(commandPacket: commandPacket.data) { data, error in + if let error = error { completion(.failure(error)); return } + completion(.success(FlutterStandardTypedData(bytes: data))) + } + } + + func miFareSendMiFareCommand(handle: String, commandPacket: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCMiFareTag else { completion(.failure(NSError())); return } + tag.sendMiFareCommand(commandPacket: commandPacket.data) { data, error in + if let error = error { completion(.failure(error)); return } + completion(.success(FlutterStandardTypedData(bytes: data))) + } + } + + func miFareSendMiFareISO7816Command(handle: String, apdu: PigeonISO7816APDU, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCMiFareTag else { completion(.failure(NSError())); return } + tag.sendMiFareISO7816Command(convert(apdu)) { payload, statusWord1, statusWord2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonISO7816ResponseAPDU( + payload: FlutterStandardTypedData(bytes: payload), + statusWord1: Int64(statusWord1), + statusWord2: Int64(statusWord2) + ))) + } + } + + func miFareSendMiFareISO7816CommandRaw(handle: String, data: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCMiFareTag else { completion(.failure(NSError())); return } + tag.sendMiFareISO7816Command(NFCISO7816APDU(data: data.data)!) { payload, statusWord1, statusWord2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonISO7816ResponseAPDU( + payload: FlutterStandardTypedData(bytes: payload), + statusWord1: Int64(statusWord1), + statusWord2: Int64(statusWord2) + ))) + } + } + + func iso7816SendCommand(handle: String, apdu: PigeonISO7816APDU, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO7816Tag else { completion(.failure(NSError())); return } + tag.sendCommand(apdu: convert(apdu)) { payload, statusWord1, statusWord2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonISO7816ResponseAPDU( + payload: FlutterStandardTypedData(bytes: payload), + statusWord1: Int64(statusWord1), + statusWord2: Int64(statusWord2) + ))) + } + } + + func iso7816SendCommandRaw(handle: String, data: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO7816Tag else { completion(.failure(NSError())); return } + tag.sendCommand(apdu: NFCISO7816APDU(data: data.data)!) { payload, statusWord1, statusWord2, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonISO7816ResponseAPDU( + payload: FlutterStandardTypedData(bytes: payload), + statusWord1: Int64(statusWord1), + statusWord2: Int64(statusWord2) + ))) + } + } + + func iso15693StayQuiet(handle: String, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.stayQuiet() { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693ReadSingleBlock(handle: String, requestFlags: [String], blockNumber: Int64, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.readSingleBlock(requestFlags: convert(requestFlags), blockNumber: UInt8(blockNumber)) { dataBlock, error in + if let error = error { completion(.failure(error)); return } + completion(.success(FlutterStandardTypedData(bytes: dataBlock))) + } + } + + func iso15693WriteSingleBlock(handle: String, requestFlags: [String], blockNumber: Int64, dataBlock: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.writeSingleBlock(requestFlags: convert(requestFlags), blockNumber: UInt8(blockNumber), dataBlock: dataBlock.data) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693LockBlock(handle: String, requestFlags: [String], blockNumber: Int64, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.lockBlock(requestFlags: convert(requestFlags), blockNumber: UInt8(blockNumber)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693ReadMultipleBlocks(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.readMultipleBlocks(requestFlags: convert(requestFlags), blockRange: convert(blockNumber, numberOfBlocks)) { dataBlocks, error in + if let error = error { completion(.failure(error)); return } + completion(.success(dataBlocks.map { FlutterStandardTypedData(bytes: $0) })) + } + } + + func iso15693WriteMultipleBlocks(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, dataBlocks: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.writeMultipleBlocks(requestFlags: convert(requestFlags), blockRange: convert(blockNumber, numberOfBlocks), dataBlocks: dataBlocks.map { $0.data }) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693Select(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.select(requestFlags: convert(requestFlags)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693ResetToReady(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.resetToReady(requestFlags: convert(requestFlags)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693WriteAfi(handle: String, requestFlags: [String], afi: Int64, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.writeAFI(requestFlags: convert(requestFlags), afi: UInt8(afi)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693LockAfi(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.lockAFI(requestFlags: convert(requestFlags)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693WriteDsfId(handle: String, requestFlags: [String], dsfId: Int64, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.writeDSFID(requestFlags: convert(requestFlags), dsfid: UInt8(dsfId)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693LockDsfId(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.lockDFSID(requestFlags: convert(requestFlags)) { error in + if let error = error { completion(.failure(error)); return } + completion(.success(())) + } + } + + func iso15693GetSystemInfo(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.getSystemInfo(requestFlags: convert(requestFlags)) { dataStorageFormatIdentifier, applicationFamilyIdentifier, blockSize, totalBlocks, icReference, error in + if let error = error { completion(.failure(error)); return } + completion(.success(PigeonISO15693SystemInfo( + dataStorageFormatIdentifier: Int64(dataStorageFormatIdentifier), + applicationFamilyIdentifier: Int64(applicationFamilyIdentifier), + blockSize: Int64(blockSize), + totalBlocks: Int64(totalBlocks), + icReference: Int64(icReference) + ))) + } + } + + func iso15693GetMultipleBlockSecurityStatus(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, completion: @escaping (Result<[Int64], Error>) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.getMultipleBlockSecurityStatus(requestFlags: convert(requestFlags), blockRange: convert(blockNumber, numberOfBlocks)) { status, error in + if let error = error { completion(.failure(error)); return } + completion(.success(status.map { Int64(truncating: $0) })) + } + } + + func iso15693CustomCommand(handle: String, requestFlags: [String], customCommandCode: Int64, customRequestParameters: FlutterStandardTypedData, completion: @escaping (Result) -> Void) { + guard #available(iOS 13.0, *) else { completion(.failure(NSError())); return; } + guard let tag = cachedTags[handle] as? NFCISO15693Tag else { completion(.failure(NSError())); return } + tag.customCommand(requestFlags: convert(requestFlags), customCommandCode: Int(customCommandCode), customRequestParameters: customRequestParameters.data) { data, error in + if let error = error { completion(.failure(error)); return } + completion(.success(FlutterStandardTypedData(bytes: data))) + } + } +} + +extension NfcManagerPlugin: NFCTagReaderSessionDelegate { + @available(iOS 13.0, *) + public func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) { + flutterApi.tagReaderSessionDidBecomeActive { _ in /* no op */ } + } + + @available(iOS 13.0, *) + public func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) { + let pigeonError = PigeonNfcReaderSessionError( + code: convert((error as! NFCReaderError).code), + message: error.localizedDescription + ) + flutterApi.tagReaderSessionDidInvalidateWithError(error: pigeonError) { _ in /* no op */ } + } + + @available(iOS 13.0, *) + public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) { + session.connect(to: tags.first!) { error in + if let error = error { + // skip tag detection + print(error) + if !self.shouldInvalidateSessionAfterFirstRead { session.restartPolling() } + return + } + convert(tags.first!) { tag, pigeon, error in + if let error = error { + // skip tag detection + print(error) + if !self.shouldInvalidateSessionAfterFirstRead { session.restartPolling() } + return + } + guard let pigeon = pigeon else { + // skip tag detection + if !self.shouldInvalidateSessionAfterFirstRead { session.restartPolling() } + return + } + self.cachedTags[pigeon.handle] = tag + self.flutterApi.tagReaderSessionDidDetect(tag: pigeon) { _ in /* no op */ } + if !self.shouldInvalidateSessionAfterFirstRead { session.restartPolling() } + } + } + } +} + +extension NfcManagerPlugin: NFCVASReaderSessionDelegate { + @available(iOS 13.0, *) + public func readerSessionDidBecomeActive(_ session: NFCVASReaderSession) { + flutterApi.vasReaderSessionDidBecomeActive { _ in /* no op */ } + } + + @available(iOS 13.0, *) + public func readerSession(_ session: NFCVASReaderSession, didInvalidateWithError error: Error) { + let pigeonError = PigeonNfcReaderSessionError( + code: convert((error as! NFCReaderError).code), + message: error.localizedDescription + ) + flutterApi.vasReaderSessionDidInvalidateWithError(error: pigeonError) { _ in /* no op */ } + } + + @available(iOS 13.0, *) + public func readerSession(_ session: NFCVASReaderSession, didReceive responses: [NFCVASResponse]) { + flutterApi.vasReaderSessionDidReceive(responses: responses.map { convert($0) }) { _ in /* no op */ } + } +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCTag, _ completionHandler: @escaping (NFCNDEFTag, PigeonTag?, Error?) -> Void) { + switch (value) { + case .feliCa(let tag): convert(tag) { pigeon, error in completionHandler(tag, pigeon, error) } + case .iso15693(let tag): convert(tag) { pigeon, error in completionHandler(tag, pigeon, error) } + case .iso7816(let tag): convert(tag) { pigeon, error in completionHandler(tag, pigeon, error) } + case .miFare(let tag): convert(tag) { pigeon, error in completionHandler(tag, pigeon, error) } + @unknown default: print("Unknown tag cannot be serialized") + } +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCNDEFTag, _ completionHandler: @escaping (PigeonTag?, Error?) -> Void) { + var pigeon = PigeonTag(handle: NSUUID().uuidString) + + if let value = value as? NFCFeliCaTag { + pigeon.feliCa = PigeonFeliCa( + currentSystemCode: FlutterStandardTypedData(bytes: value.currentSystemCode), + currentIDm: FlutterStandardTypedData(bytes: value.currentIDm) + ) + } + else if let value = value as? NFCISO15693Tag { + pigeon.iso15693 = PigeonISO15693( + icManufacturerCode: Int64(value.icManufacturerCode), + icSerialNumber: FlutterStandardTypedData(bytes: value.icSerialNumber), + identifier: FlutterStandardTypedData(bytes: value.identifier) + ) + } + else if let value = value as? NFCISO7816Tag { + pigeon.iso7816 = PigeonISO7816( + initialSelectedAID: value.initialSelectedAID, + identifier: FlutterStandardTypedData(bytes: value.identifier), + historicalBytes: value.historicalBytes != nil ? FlutterStandardTypedData(bytes: value.historicalBytes!) : nil, + applicationData: value.applicationData != nil ? FlutterStandardTypedData(bytes: value.applicationData!) : nil, + proprietaryApplicationDataCoding: value.proprietaryApplicationDataCoding + ) + } + else if let value = value as? NFCMiFareTag { + pigeon.miFare = PigeonMiFare( + mifareFamily: convert(value.mifareFamily), + identifier: FlutterStandardTypedData(bytes: value.identifier), + historicalBytes: value.historicalBytes != nil ? FlutterStandardTypedData(bytes: value.historicalBytes!) : nil + ) + } + + value.queryNDEFStatus { status, capacity, error in + if let error = error { + completionHandler(nil, error) + return + } + pigeon.ndef = PigeonNdef( + status: convert(status), + capacity: Int64(capacity) + ) + if status == .notSupported { + completionHandler(pigeon, nil) + return + } + value.readNDEF { message, error in + if let error = error { + completionHandler(nil, error) + return + } + if let message = message { + pigeon.ndef?.cachedNdefMessage = convert(message) + } + completionHandler(pigeon, nil) + } + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonNdefMessage) -> NFCNDEFMessage { + return NFCNDEFMessage( + records: value.records.map { NFCNDEFPayload( + format: convert($0!.typeNameFormat), + type: $0!.type.data, + identifier: $0!.identifier.data, + payload: $0!.payload.data + ) } + ) +} + +private func convert(_ value: NFCNDEFMessage) -> PigeonNdefMessage { + return PigeonNdefMessage(records: value.records.map { convert($0) }) +} + +private func convert(_ value: NFCNDEFPayload) -> PigeonNdefPayload { + return PigeonNdefPayload( + typeNameFormat: convert(value.typeNameFormat), + type: FlutterStandardTypedData(bytes: value.type), + identifier: FlutterStandardTypedData(bytes: value.identifier), + payload: FlutterStandardTypedData(bytes: value.payload) + ) +} + +@available(iOS 13.0, *) +private func convert(_ value: [String]) -> NFCTagReaderSession.PollingOption { + var option = NFCTagReaderSession.PollingOption() + value.forEach { option.insert(convert($0)) } + return option +} + +@available(iOS 13.0, *) +private func convert(_ value: String) -> NFCTagReaderSession.PollingOption { + switch (value) { + case "iso14443": return .iso14443 + case "iso15693": return .iso15693 + case "iso18092": return .iso18092 + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCNDEFStatus) -> PigeonNdefStatus { + switch (value) { + case .notSupported: return .notSupported + case .readWrite: return .readWrite + case .readOnly: return .readOnly + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonFeliCaPollingRequestCode) -> PollingRequestCode { + switch (value) { + case .noRequest: return .noRequest + case .systemCode: return .systemCode + case .communicationPerformance: return .communicationPerformance + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonFeliCaPollingTimeSlot) -> PollingTimeSlot { + switch (value) { + case .max1: return .max1 + case .max2: return .max2 + case .max4: return .max4 + case .max8: return .max8 + case .max16: return .max16 + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonISO7816APDU) -> NFCISO7816APDU { + return NFCISO7816APDU( + instructionClass: UInt8(value.instructionClass), + instructionCode: UInt8(value.instructionCode), + p1Parameter: UInt8(value.p1Parameter), + p2Parameter: UInt8(value.p2Parameter), + data: value.data.data, + expectedResponseLength: Int(value.expectedResponseLength) + ) +} + +private func convert(_ value: [String]) -> RequestFlag { + var flag = RequestFlag() + value.forEach { flag.insert(convert($0)) } + return flag +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonNfcVasCommandConfiguration) -> NFCVASCommandConfiguration { + return NFCVASCommandConfiguration( + vasMode: convert(value.mode), + passTypeIdentifier: value.passIdentifier, + url: (value.url == nil) ? nil : URL(string: value.url!) + ) +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCVASResponse) -> PigeonNfcVasResponse { + return PigeonNfcVasResponse( + status: convert(value.status), + vasData: FlutterStandardTypedData(bytes: value.vasData), + mobileToken: FlutterStandardTypedData(bytes: value.mobileToken) + ) +} + +private func convert(_ value: String) -> RequestFlag { + switch (value) { + case "address": return .address + case "dualSubCarriers": return .dualSubCarriers + case "highDataRate": return .highDataRate + case "option": return .option + case "protocolExtension": return .protocolExtension + case "select": return .select + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCMiFareFamily) -> PigeonMiFareFamily { + switch (value) { + case .unknown: return .unknown + case .ultralight: return .ultralight + case .plus: return .plus + case .desfire: return .desfire + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonTypeNameFormat) -> NFCTypeNameFormat { + switch (value) { + case .empty: return .empty + case .wellKnown: return .nfcWellKnown + case .media: return .media + case .absoluteUri: return .absoluteURI + case .external: return .nfcExternal + case .unknown: return .unknown + case .unchanged: return .unchanged + } +} + +private func convert(_ value: NFCTypeNameFormat) -> PigeonTypeNameFormat { + switch (value) { + case .empty: return .empty + case .nfcWellKnown: return .wellKnown + case .media: return .media + case .absoluteURI: return .absoluteUri + case .nfcExternal: return .external + case .unknown: return .unknown + case .unchanged: return .unchanged + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: PigeonNfcVasCommandConfigurationMode) -> NFCVASCommandConfiguration.Mode { + switch value { + case .normal: return .normal + case .urlOnly: return .urlOnly + } +} + +private func convert(_ value: NFCReaderError.Code) -> PigeonNfcReaderErrorCode { + switch value { + case .readerSessionInvalidationErrorFirstNDEFTagRead: return .readerSessionInvalidationErrorFirstNDEFTagRead + case .readerSessionInvalidationErrorSessionTerminatedUnexpectedly: return .readerSessionInvalidationErrorSessionTerminatedUnexpectedly + case .readerSessionInvalidationErrorSessionTimeout: return .readerSessionInvalidationErrorSessionTimeout + case .readerSessionInvalidationErrorSystemIsBusy: return .readerSessionInvalidationErrorSystemIsBusy + case .readerSessionInvalidationErrorUserCanceled: return .readerSessionInvalidationErrorUserCanceled + case .ndefReaderSessionErrorTagNotWritable: return .ndefReaderSessionErrorTagNotWritable + case .ndefReaderSessionErrorTagSizeTooSmall: return .ndefReaderSessionErrorTagSizeTooSmall + case .ndefReaderSessionErrorTagUpdateFailure: return .ndefReaderSessionErrorTagUpdateFailure + case .ndefReaderSessionErrorZeroLengthMessage: return .ndefReaderSessionErrorZeroLengthMessage + case .readerTransceiveErrorRetryExceeded: return .readerTransceiveErrorRetryExceeded + case .readerTransceiveErrorTagConnectionLost: return .readerTransceiveErrorTagConnectionLost + case .readerTransceiveErrorTagNotConnected: return .readerTransceiveErrorTagNotConnected + case .readerTransceiveErrorTagResponseError: return .readerTransceiveErrorTagResponseError + case .readerTransceiveErrorSessionInvalidated: return .readerTransceiveErrorSessionInvalidated + case .readerTransceiveErrorPacketTooLong: return .readerTransceiveErrorPacketTooLong + case .tagCommandConfigurationErrorInvalidParameters: return .tagCommandConfigurationErrorInvalidParameters + case .readerErrorUnsupportedFeature: return .readerErrorUnsupportedFeature + case .readerErrorInvalidParameter: return .readerErrorInvalidParameter + case .readerErrorInvalidParameterLength: return .readerErrorInvalidParameterLength + case .readerErrorParameterOutOfBound: return .readerErrorParameterOutOfBound + case .readerErrorRadioDisabled: return .readerErrorRadioDisabled + case .readerErrorSecurityViolation: return .readerErrorSecurityViolation + default: fatalError() + } +} + +@available(iOS 13.0, *) +private func convert(_ value: NFCVASResponse.ErrorCode) -> PigeonNfcVasResponseErrorCode { + switch (value) { + case .success: return .success + case .userIntervention: return .userIntervention + case .dataNotActivated: return .dataNotActivated + case .dataNotFound: return .dataNotFound + case .incorrectData: return .incorrectData + case .unsupportedApplicationVersion: return .unsupportedApplicationVersion + case .wrongLCField: return .wrongLCField + case .wrongParameters: return .wrongParameters + default: fatalError() + } +} + +private func convert(_ value1: Int64, _ value2: Int64) -> NSRange { + return NSRange(location: Int(value1), length: Int(value2)) +} + +extension FlutterError: Swift.Error {} + diff --git a/ios/Classes/Pigeon.swift b/ios/Classes/Pigeon.swift new file mode 100644 index 0000000..1c806e9 --- /dev/null +++ b/ios/Classes/Pigeon.swift @@ -0,0 +1,1804 @@ +// Autogenerated from Pigeon (v15.0.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation +#if os(iOS) +import Flutter +#elseif os(macOS) +import FlutterMacOS +#else +#error("Unsupported platform.") +#endif + +private func wrapResult(_ result: Any?) -> [Any?] { + return [result] +} + +private func wrapError(_ error: Any) -> [Any?] { + if let flutterError = error as? FlutterError { + return [ + flutterError.code, + flutterError.message, + flutterError.details + ] + } + return [ + "\(error)", + "\(type(of: error))", + "Stacktrace: \(Thread.callStackSymbols)" + ] +} + +private func createConnectionError(withChannelName channelName: String) -> FlutterError { + return FlutterError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +enum PigeonNdefStatus: Int { + case notSupported = 0 + case readWrite = 1 + case readOnly = 2 +} + +enum PigeonTypeNameFormat: Int { + case empty = 0 + case wellKnown = 1 + case media = 2 + case absoluteUri = 3 + case external = 4 + case unknown = 5 + case unchanged = 6 +} + +enum PigeonFeliCaPollingRequestCode: Int { + case noRequest = 0 + case systemCode = 1 + case communicationPerformance = 2 +} + +enum PigeonFeliCaPollingTimeSlot: Int { + case max1 = 0 + case max2 = 1 + case max4 = 2 + case max8 = 3 + case max16 = 4 +} + +enum PigeonMiFareFamily: Int { + case unknown = 0 + case ultralight = 1 + case plus = 2 + case desfire = 3 +} + +enum PigeonNfcVasCommandConfigurationMode: Int { + case normal = 0 + case urlOnly = 1 +} + +enum PigeonNfcReaderErrorCode: Int { + case readerSessionInvalidationErrorFirstNDEFTagRead = 0 + case readerSessionInvalidationErrorSessionTerminatedUnexpectedly = 1 + case readerSessionInvalidationErrorSessionTimeout = 2 + case readerSessionInvalidationErrorSystemIsBusy = 3 + case readerSessionInvalidationErrorUserCanceled = 4 + case ndefReaderSessionErrorTagNotWritable = 5 + case ndefReaderSessionErrorTagSizeTooSmall = 6 + case ndefReaderSessionErrorTagUpdateFailure = 7 + case ndefReaderSessionErrorZeroLengthMessage = 8 + case readerTransceiveErrorRetryExceeded = 9 + case readerTransceiveErrorTagConnectionLost = 10 + case readerTransceiveErrorTagNotConnected = 11 + case readerTransceiveErrorTagResponseError = 12 + case readerTransceiveErrorSessionInvalidated = 13 + case readerTransceiveErrorPacketTooLong = 14 + case tagCommandConfigurationErrorInvalidParameters = 15 + case readerErrorUnsupportedFeature = 16 + case readerErrorInvalidParameter = 17 + case readerErrorInvalidParameterLength = 18 + case readerErrorParameterOutOfBound = 19 + case readerErrorRadioDisabled = 20 + case readerErrorSecurityViolation = 21 +} + +enum PigeonNfcVasResponseErrorCode: Int { + case success = 0 + case userIntervention = 1 + case dataNotActivated = 2 + case dataNotFound = 3 + case incorrectData = 4 + case unsupportedApplicationVersion = 5 + case wrongLCField = 6 + case wrongParameters = 7 +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonTag { + var handle: String + var ndef: PigeonNdef? = nil + var feliCa: PigeonFeliCa? = nil + var iso15693: PigeonISO15693? = nil + var iso7816: PigeonISO7816? = nil + var miFare: PigeonMiFare? = nil + + static func fromList(_ list: [Any?]) -> PigeonTag? { + let handle = list[0] as! String + var ndef: PigeonNdef? = nil + if let ndefList: [Any?] = nilOrValue(list[1]) { + ndef = PigeonNdef.fromList(ndefList) + } + var feliCa: PigeonFeliCa? = nil + if let feliCaList: [Any?] = nilOrValue(list[2]) { + feliCa = PigeonFeliCa.fromList(feliCaList) + } + var iso15693: PigeonISO15693? = nil + if let iso15693List: [Any?] = nilOrValue(list[3]) { + iso15693 = PigeonISO15693.fromList(iso15693List) + } + var iso7816: PigeonISO7816? = nil + if let iso7816List: [Any?] = nilOrValue(list[4]) { + iso7816 = PigeonISO7816.fromList(iso7816List) + } + var miFare: PigeonMiFare? = nil + if let miFareList: [Any?] = nilOrValue(list[5]) { + miFare = PigeonMiFare.fromList(miFareList) + } + + return PigeonTag( + handle: handle, + ndef: ndef, + feliCa: feliCa, + iso15693: iso15693, + iso7816: iso7816, + miFare: miFare + ) + } + func toList() -> [Any?] { + return [ + handle, + ndef?.toList(), + feliCa?.toList(), + iso15693?.toList(), + iso7816?.toList(), + miFare?.toList(), + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNdef { + var status: PigeonNdefStatus + var capacity: Int64 + var cachedNdefMessage: PigeonNdefMessage? = nil + + static func fromList(_ list: [Any?]) -> PigeonNdef? { + let status = PigeonNdefStatus(rawValue: list[0] as! Int)! + let capacity = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + var cachedNdefMessage: PigeonNdefMessage? = nil + if let cachedNdefMessageList: [Any?] = nilOrValue(list[2]) { + cachedNdefMessage = PigeonNdefMessage.fromList(cachedNdefMessageList) + } + + return PigeonNdef( + status: status, + capacity: capacity, + cachedNdefMessage: cachedNdefMessage + ) + } + func toList() -> [Any?] { + return [ + status.rawValue, + capacity, + cachedNdefMessage?.toList(), + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCa { + var currentSystemCode: FlutterStandardTypedData + var currentIDm: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonFeliCa? { + let currentSystemCode = list[0] as! FlutterStandardTypedData + let currentIDm = list[1] as! FlutterStandardTypedData + + return PigeonFeliCa( + currentSystemCode: currentSystemCode, + currentIDm: currentIDm + ) + } + func toList() -> [Any?] { + return [ + currentSystemCode, + currentIDm, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonISO15693 { + var icManufacturerCode: Int64 + var icSerialNumber: FlutterStandardTypedData + var identifier: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonISO15693? { + let icManufacturerCode = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let icSerialNumber = list[1] as! FlutterStandardTypedData + let identifier = list[2] as! FlutterStandardTypedData + + return PigeonISO15693( + icManufacturerCode: icManufacturerCode, + icSerialNumber: icSerialNumber, + identifier: identifier + ) + } + func toList() -> [Any?] { + return [ + icManufacturerCode, + icSerialNumber, + identifier, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonISO7816 { + var initialSelectedAID: String + var identifier: FlutterStandardTypedData + var historicalBytes: FlutterStandardTypedData? = nil + var applicationData: FlutterStandardTypedData? = nil + var proprietaryApplicationDataCoding: Bool + + static func fromList(_ list: [Any?]) -> PigeonISO7816? { + let initialSelectedAID = list[0] as! String + let identifier = list[1] as! FlutterStandardTypedData + let historicalBytes: FlutterStandardTypedData? = nilOrValue(list[2]) + let applicationData: FlutterStandardTypedData? = nilOrValue(list[3]) + let proprietaryApplicationDataCoding = list[4] as! Bool + + return PigeonISO7816( + initialSelectedAID: initialSelectedAID, + identifier: identifier, + historicalBytes: historicalBytes, + applicationData: applicationData, + proprietaryApplicationDataCoding: proprietaryApplicationDataCoding + ) + } + func toList() -> [Any?] { + return [ + initialSelectedAID, + identifier, + historicalBytes, + applicationData, + proprietaryApplicationDataCoding, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonMiFare { + var mifareFamily: PigeonMiFareFamily + var identifier: FlutterStandardTypedData + var historicalBytes: FlutterStandardTypedData? = nil + + static func fromList(_ list: [Any?]) -> PigeonMiFare? { + let mifareFamily = PigeonMiFareFamily(rawValue: list[0] as! Int)! + let identifier = list[1] as! FlutterStandardTypedData + let historicalBytes: FlutterStandardTypedData? = nilOrValue(list[2]) + + return PigeonMiFare( + mifareFamily: mifareFamily, + identifier: identifier, + historicalBytes: historicalBytes + ) + } + func toList() -> [Any?] { + return [ + mifareFamily.rawValue, + identifier, + historicalBytes, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNDEFQueryStatus { + var status: PigeonNdefStatus + var capacity: Int64 + + static func fromList(_ list: [Any?]) -> PigeonNDEFQueryStatus? { + let status = PigeonNdefStatus(rawValue: list[0] as! Int)! + let capacity = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + + return PigeonNDEFQueryStatus( + status: status, + capacity: capacity + ) + } + func toList() -> [Any?] { + return [ + status.rawValue, + capacity, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNdefMessage { + var records: [PigeonNdefPayload?] + + static func fromList(_ list: [Any?]) -> PigeonNdefMessage? { + let records = list[0] as! [PigeonNdefPayload?] + + return PigeonNdefMessage( + records: records + ) + } + func toList() -> [Any?] { + return [ + records, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNdefPayload { + var typeNameFormat: PigeonTypeNameFormat + var type: FlutterStandardTypedData + var identifier: FlutterStandardTypedData + var payload: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonNdefPayload? { + let typeNameFormat = PigeonTypeNameFormat(rawValue: list[0] as! Int)! + let type = list[1] as! FlutterStandardTypedData + let identifier = list[2] as! FlutterStandardTypedData + let payload = list[3] as! FlutterStandardTypedData + + return PigeonNdefPayload( + typeNameFormat: typeNameFormat, + type: type, + identifier: identifier, + payload: payload + ) + } + func toList() -> [Any?] { + return [ + typeNameFormat.rawValue, + type, + identifier, + payload, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCaPollingResponse { + var manufacturerParameter: FlutterStandardTypedData + var requestData: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonFeliCaPollingResponse? { + let manufacturerParameter = list[0] as! FlutterStandardTypedData + let requestData = list[1] as! FlutterStandardTypedData + + return PigeonFeliCaPollingResponse( + manufacturerParameter: manufacturerParameter, + requestData: requestData + ) + } + func toList() -> [Any?] { + return [ + manufacturerParameter, + requestData, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCaReadWithoutEncryptionResponse { + var statusFlag1: Int64 + var statusFlag2: Int64 + var blockData: [FlutterStandardTypedData?] + + static func fromList(_ list: [Any?]) -> PigeonFeliCaReadWithoutEncryptionResponse? { + let statusFlag1 = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let statusFlag2 = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let blockData = list[2] as! [FlutterStandardTypedData?] + + return PigeonFeliCaReadWithoutEncryptionResponse( + statusFlag1: statusFlag1, + statusFlag2: statusFlag2, + blockData: blockData + ) + } + func toList() -> [Any?] { + return [ + statusFlag1, + statusFlag2, + blockData, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCaRequestServiceV2Response { + var statusFlag1: Int64 + var statusFlag2: Int64 + var encryptionIdentifier: Int64 + var nodeKeyVersionListAES: [FlutterStandardTypedData?] + var nodeKeyVersionListDES: [FlutterStandardTypedData?] + + static func fromList(_ list: [Any?]) -> PigeonFeliCaRequestServiceV2Response? { + let statusFlag1 = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let statusFlag2 = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let encryptionIdentifier = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) + let nodeKeyVersionListAES = list[3] as! [FlutterStandardTypedData?] + let nodeKeyVersionListDES = list[4] as! [FlutterStandardTypedData?] + + return PigeonFeliCaRequestServiceV2Response( + statusFlag1: statusFlag1, + statusFlag2: statusFlag2, + encryptionIdentifier: encryptionIdentifier, + nodeKeyVersionListAES: nodeKeyVersionListAES, + nodeKeyVersionListDES: nodeKeyVersionListDES + ) + } + func toList() -> [Any?] { + return [ + statusFlag1, + statusFlag2, + encryptionIdentifier, + nodeKeyVersionListAES, + nodeKeyVersionListDES, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCaRequestSpecificationVersionResponse { + var statusFlag1: Int64 + var statusFlag2: Int64 + var basicVersion: FlutterStandardTypedData + var optionVersion: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonFeliCaRequestSpecificationVersionResponse? { + let statusFlag1 = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let statusFlag2 = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let basicVersion = list[2] as! FlutterStandardTypedData + let optionVersion = list[3] as! FlutterStandardTypedData + + return PigeonFeliCaRequestSpecificationVersionResponse( + statusFlag1: statusFlag1, + statusFlag2: statusFlag2, + basicVersion: basicVersion, + optionVersion: optionVersion + ) + } + func toList() -> [Any?] { + return [ + statusFlag1, + statusFlag2, + basicVersion, + optionVersion, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonFeliCaStatusFlag { + var statusFlag1: Int64 + var statusFlag2: Int64 + + static func fromList(_ list: [Any?]) -> PigeonFeliCaStatusFlag? { + let statusFlag1 = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let statusFlag2 = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + + return PigeonFeliCaStatusFlag( + statusFlag1: statusFlag1, + statusFlag2: statusFlag2 + ) + } + func toList() -> [Any?] { + return [ + statusFlag1, + statusFlag2, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonISO7816APDU { + var instructionClass: Int64 + var instructionCode: Int64 + var p1Parameter: Int64 + var p2Parameter: Int64 + var data: FlutterStandardTypedData + var expectedResponseLength: Int64 + + static func fromList(_ list: [Any?]) -> PigeonISO7816APDU? { + let instructionClass = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let instructionCode = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let p1Parameter = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) + let p2Parameter = list[3] is Int64 ? list[3] as! Int64 : Int64(list[3] as! Int32) + let data = list[4] as! FlutterStandardTypedData + let expectedResponseLength = list[5] is Int64 ? list[5] as! Int64 : Int64(list[5] as! Int32) + + return PigeonISO7816APDU( + instructionClass: instructionClass, + instructionCode: instructionCode, + p1Parameter: p1Parameter, + p2Parameter: p2Parameter, + data: data, + expectedResponseLength: expectedResponseLength + ) + } + func toList() -> [Any?] { + return [ + instructionClass, + instructionCode, + p1Parameter, + p2Parameter, + data, + expectedResponseLength, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonISO7816ResponseAPDU { + var payload: FlutterStandardTypedData + var statusWord1: Int64 + var statusWord2: Int64 + + static func fromList(_ list: [Any?]) -> PigeonISO7816ResponseAPDU? { + let payload = list[0] as! FlutterStandardTypedData + let statusWord1 = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let statusWord2 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) + + return PigeonISO7816ResponseAPDU( + payload: payload, + statusWord1: statusWord1, + statusWord2: statusWord2 + ) + } + func toList() -> [Any?] { + return [ + payload, + statusWord1, + statusWord2, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonISO15693SystemInfo { + var dataStorageFormatIdentifier: Int64 + var applicationFamilyIdentifier: Int64 + var blockSize: Int64 + var totalBlocks: Int64 + var icReference: Int64 + + static func fromList(_ list: [Any?]) -> PigeonISO15693SystemInfo? { + let dataStorageFormatIdentifier = list[0] is Int64 ? list[0] as! Int64 : Int64(list[0] as! Int32) + let applicationFamilyIdentifier = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32) + let blockSize = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32) + let totalBlocks = list[3] is Int64 ? list[3] as! Int64 : Int64(list[3] as! Int32) + let icReference = list[4] is Int64 ? list[4] as! Int64 : Int64(list[4] as! Int32) + + return PigeonISO15693SystemInfo( + dataStorageFormatIdentifier: dataStorageFormatIdentifier, + applicationFamilyIdentifier: applicationFamilyIdentifier, + blockSize: blockSize, + totalBlocks: totalBlocks, + icReference: icReference + ) + } + func toList() -> [Any?] { + return [ + dataStorageFormatIdentifier, + applicationFamilyIdentifier, + blockSize, + totalBlocks, + icReference, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNfcReaderSessionError { + var code: PigeonNfcReaderErrorCode + var message: String + + static func fromList(_ list: [Any?]) -> PigeonNfcReaderSessionError? { + let code = PigeonNfcReaderErrorCode(rawValue: list[0] as! Int)! + let message = list[1] as! String + + return PigeonNfcReaderSessionError( + code: code, + message: message + ) + } + func toList() -> [Any?] { + return [ + code.rawValue, + message, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNfcVasCommandConfiguration { + var mode: PigeonNfcVasCommandConfigurationMode + var passIdentifier: String + var url: String? = nil + + static func fromList(_ list: [Any?]) -> PigeonNfcVasCommandConfiguration? { + let mode = PigeonNfcVasCommandConfigurationMode(rawValue: list[0] as! Int)! + let passIdentifier = list[1] as! String + let url: String? = nilOrValue(list[2]) + + return PigeonNfcVasCommandConfiguration( + mode: mode, + passIdentifier: passIdentifier, + url: url + ) + } + func toList() -> [Any?] { + return [ + mode.rawValue, + passIdentifier, + url, + ] + } +} + +/// Generated class from Pigeon that represents data sent in messages. +struct PigeonNfcVasResponse { + var status: PigeonNfcVasResponseErrorCode + var vasData: FlutterStandardTypedData + var mobileToken: FlutterStandardTypedData + + static func fromList(_ list: [Any?]) -> PigeonNfcVasResponse? { + let status = PigeonNfcVasResponseErrorCode(rawValue: list[0] as! Int)! + let vasData = list[1] as! FlutterStandardTypedData + let mobileToken = list[2] as! FlutterStandardTypedData + + return PigeonNfcVasResponse( + status: status, + vasData: vasData, + mobileToken: mobileToken + ) + } + func toList() -> [Any?] { + return [ + status.rawValue, + vasData, + mobileToken, + ] + } +} + +private class PigeonFlutterApiCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return PigeonFeliCa.fromList(self.readValue() as! [Any?]) + case 129: + return PigeonISO15693.fromList(self.readValue() as! [Any?]) + case 130: + return PigeonISO7816.fromList(self.readValue() as! [Any?]) + case 131: + return PigeonMiFare.fromList(self.readValue() as! [Any?]) + case 132: + return PigeonNdef.fromList(self.readValue() as! [Any?]) + case 133: + return PigeonNdefMessage.fromList(self.readValue() as! [Any?]) + case 134: + return PigeonNdefPayload.fromList(self.readValue() as! [Any?]) + case 135: + return PigeonNfcReaderSessionError.fromList(self.readValue() as! [Any?]) + case 136: + return PigeonNfcVasResponse.fromList(self.readValue() as! [Any?]) + case 137: + return PigeonTag.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class PigeonFlutterApiCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? PigeonFeliCa { + super.writeByte(128) + super.writeValue(value.toList()) + } else if let value = value as? PigeonISO15693 { + super.writeByte(129) + super.writeValue(value.toList()) + } else if let value = value as? PigeonISO7816 { + super.writeByte(130) + super.writeValue(value.toList()) + } else if let value = value as? PigeonMiFare { + super.writeByte(131) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdef { + super.writeByte(132) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdefMessage { + super.writeByte(133) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdefPayload { + super.writeByte(134) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNfcReaderSessionError { + super.writeByte(135) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNfcVasResponse { + super.writeByte(136) + super.writeValue(value.toList()) + } else if let value = value as? PigeonTag { + super.writeByte(137) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class PigeonFlutterApiCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return PigeonFlutterApiCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return PigeonFlutterApiCodecWriter(data: data) + } +} + +class PigeonFlutterApiCodec: FlutterStandardMessageCodec { + static let shared = PigeonFlutterApiCodec(readerWriter: PigeonFlutterApiCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol PigeonFlutterApiProtocol { + func tagReaderSessionDidBecomeActive(completion: @escaping (Result) -> Void) + func tagReaderSessionDidDetect(tag tagArg: PigeonTag, completion: @escaping (Result) -> Void) + func tagReaderSessionDidInvalidateWithError(error errorArg: PigeonNfcReaderSessionError, completion: @escaping (Result) -> Void) + func vasReaderSessionDidBecomeActive(completion: @escaping (Result) -> Void) + func vasReaderSessionDidReceive(responses responsesArg: [PigeonNfcVasResponse], completion: @escaping (Result) -> Void) + func vasReaderSessionDidInvalidateWithError(error errorArg: PigeonNfcReaderSessionError, completion: @escaping (Result) -> Void) +} +class PigeonFlutterApi: PigeonFlutterApiProtocol { + private let binaryMessenger: FlutterBinaryMessenger + init(binaryMessenger: FlutterBinaryMessenger){ + self.binaryMessenger = binaryMessenger + } + var codec: FlutterStandardMessageCodec { + return PigeonFlutterApiCodec.shared + } + func tagReaderSessionDidBecomeActive(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidBecomeActive" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } + func tagReaderSessionDidDetect(tag tagArg: PigeonTag, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidDetect" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([tagArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } + func tagReaderSessionDidInvalidateWithError(error errorArg: PigeonNfcReaderSessionError, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidInvalidateWithError" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([errorArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } + func vasReaderSessionDidBecomeActive(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidBecomeActive" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } + func vasReaderSessionDidReceive(responses responsesArg: [PigeonNfcVasResponse], completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidReceive" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([responsesArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } + func vasReaderSessionDidInvalidateWithError(error errorArg: PigeonNfcReaderSessionError, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidInvalidateWithError" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([errorArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName:channelName))) + return + } + if (listResponse.count > 1) { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(FlutterError(code: code, message: message, details: details))); + } else { + completion(.success(Void())) + } + } + } +} +private class PigeonHostApiCodecReader: FlutterStandardReader { + override func readValue(ofType type: UInt8) -> Any? { + switch type { + case 128: + return PigeonFeliCaPollingResponse.fromList(self.readValue() as! [Any?]) + case 129: + return PigeonFeliCaReadWithoutEncryptionResponse.fromList(self.readValue() as! [Any?]) + case 130: + return PigeonFeliCaRequestServiceV2Response.fromList(self.readValue() as! [Any?]) + case 131: + return PigeonFeliCaRequestSpecificationVersionResponse.fromList(self.readValue() as! [Any?]) + case 132: + return PigeonFeliCaStatusFlag.fromList(self.readValue() as! [Any?]) + case 133: + return PigeonISO15693SystemInfo.fromList(self.readValue() as! [Any?]) + case 134: + return PigeonISO7816APDU.fromList(self.readValue() as! [Any?]) + case 135: + return PigeonISO7816ResponseAPDU.fromList(self.readValue() as! [Any?]) + case 136: + return PigeonNDEFQueryStatus.fromList(self.readValue() as! [Any?]) + case 137: + return PigeonNdefMessage.fromList(self.readValue() as! [Any?]) + case 138: + return PigeonNdefMessage.fromList(self.readValue() as! [Any?]) + case 139: + return PigeonNdefPayload.fromList(self.readValue() as! [Any?]) + case 140: + return PigeonNfcVasCommandConfiguration.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) + } + } +} + +private class PigeonHostApiCodecWriter: FlutterStandardWriter { + override func writeValue(_ value: Any) { + if let value = value as? PigeonFeliCaPollingResponse { + super.writeByte(128) + super.writeValue(value.toList()) + } else if let value = value as? PigeonFeliCaReadWithoutEncryptionResponse { + super.writeByte(129) + super.writeValue(value.toList()) + } else if let value = value as? PigeonFeliCaRequestServiceV2Response { + super.writeByte(130) + super.writeValue(value.toList()) + } else if let value = value as? PigeonFeliCaRequestSpecificationVersionResponse { + super.writeByte(131) + super.writeValue(value.toList()) + } else if let value = value as? PigeonFeliCaStatusFlag { + super.writeByte(132) + super.writeValue(value.toList()) + } else if let value = value as? PigeonISO15693SystemInfo { + super.writeByte(133) + super.writeValue(value.toList()) + } else if let value = value as? PigeonISO7816APDU { + super.writeByte(134) + super.writeValue(value.toList()) + } else if let value = value as? PigeonISO7816ResponseAPDU { + super.writeByte(135) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNDEFQueryStatus { + super.writeByte(136) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdefMessage { + super.writeByte(137) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdefMessage { + super.writeByte(138) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNdefPayload { + super.writeByte(139) + super.writeValue(value.toList()) + } else if let value = value as? PigeonNfcVasCommandConfiguration { + super.writeByte(140) + super.writeValue(value.toList()) + } else { + super.writeValue(value) + } + } +} + +private class PigeonHostApiCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return PigeonHostApiCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return PigeonHostApiCodecWriter(data: data) + } +} + +class PigeonHostApiCodec: FlutterStandardMessageCodec { + static let shared = PigeonHostApiCodec(readerWriter: PigeonHostApiCodecReaderWriter()) +} + +/// Generated protocol from Pigeon that represents a handler of messages from Flutter. +protocol PigeonHostApi { + func tagReaderSessionReadingAvailable() throws -> Bool + func tagReaderSessionBegin(pollingOptions: [String], alertMessage: String?, invalidateAfterFirstRead: Bool) throws + func tagReaderSessionInvalidate(alertMessage: String?, errorMessage: String?) throws + func tagReaderSessionRestartPolling() throws + func tagReaderSessionSetAlertMessage(alertMessage: String) throws + func vasReaderSessionReadingAvailable() throws -> Bool + func vasReaderSessionBegin(configurations: [PigeonNfcVasCommandConfiguration], alertMessage: String?) throws + func vasReaderSessionInvalidate(alertMessage: String?, errorMessage: String?) throws + func vasReaderSessionSetAlertMessage(alertMessage: String) throws + func ndefQueryNDEFStatus(handle: String, completion: @escaping (Result) -> Void) + func ndefReadNDEF(handle: String, completion: @escaping (Result) -> Void) + func ndefWriteNDEF(handle: String, message: PigeonNdefMessage, completion: @escaping (Result) -> Void) + func ndefWriteLock(handle: String, completion: @escaping (Result) -> Void) + func feliCaPolling(handle: String, systemCode: FlutterStandardTypedData, requestCode: PigeonFeliCaPollingRequestCode, timeSlot: PigeonFeliCaPollingTimeSlot, completion: @escaping (Result) -> Void) + func feliCaRequestService(handle: String, nodeCodeList: [FlutterStandardTypedData], completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) + func feliCaRequestResponse(handle: String, completion: @escaping (Result) -> Void) + func feliCaReadWithoutEncryption(handle: String, serviceCodeList: [FlutterStandardTypedData], blockList: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) + func feliCaWriteWithoutEncryption(handle: String, serviceCodeList: [FlutterStandardTypedData], blockList: [FlutterStandardTypedData], blockData: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) + func feliCaRequestSystemCode(handle: String, completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) + func feliCaRequestServiceV2(handle: String, nodeCodeList: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) + func feliCaRequestSpecificationVersion(handle: String, completion: @escaping (Result) -> Void) + func feliCaResetMode(handle: String, completion: @escaping (Result) -> Void) + func feliCaSendFeliCaCommand(handle: String, commandPacket: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func miFareSendMiFareCommand(handle: String, commandPacket: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func miFareSendMiFareISO7816Command(handle: String, apdu: PigeonISO7816APDU, completion: @escaping (Result) -> Void) + func miFareSendMiFareISO7816CommandRaw(handle: String, data: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func iso7816SendCommand(handle: String, apdu: PigeonISO7816APDU, completion: @escaping (Result) -> Void) + func iso7816SendCommandRaw(handle: String, data: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func iso15693StayQuiet(handle: String, completion: @escaping (Result) -> Void) + func iso15693ReadSingleBlock(handle: String, requestFlags: [String], blockNumber: Int64, completion: @escaping (Result) -> Void) + func iso15693WriteSingleBlock(handle: String, requestFlags: [String], blockNumber: Int64, dataBlock: FlutterStandardTypedData, completion: @escaping (Result) -> Void) + func iso15693LockBlock(handle: String, requestFlags: [String], blockNumber: Int64, completion: @escaping (Result) -> Void) + func iso15693ReadMultipleBlocks(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, completion: @escaping (Result<[FlutterStandardTypedData], Error>) -> Void) + func iso15693WriteMultipleBlocks(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, dataBlocks: [FlutterStandardTypedData], completion: @escaping (Result) -> Void) + func iso15693Select(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) + func iso15693ResetToReady(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) + func iso15693WriteAfi(handle: String, requestFlags: [String], afi: Int64, completion: @escaping (Result) -> Void) + func iso15693LockAfi(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) + func iso15693WriteDsfId(handle: String, requestFlags: [String], dsfId: Int64, completion: @escaping (Result) -> Void) + func iso15693LockDsfId(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) + func iso15693GetSystemInfo(handle: String, requestFlags: [String], completion: @escaping (Result) -> Void) + func iso15693GetMultipleBlockSecurityStatus(handle: String, requestFlags: [String], blockNumber: Int64, numberOfBlocks: Int64, completion: @escaping (Result<[Int64], Error>) -> Void) + func iso15693CustomCommand(handle: String, requestFlags: [String], customCommandCode: Int64, customRequestParameters: FlutterStandardTypedData, completion: @escaping (Result) -> Void) +} + +/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. +class PigeonHostApiSetup { + /// The codec used by PigeonHostApi. + static var codec: FlutterStandardMessageCodec { PigeonHostApiCodec.shared } + /// Sets up an instance of `PigeonHostApi` to handle messages through the `binaryMessenger`. + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: PigeonHostApi?) { + let tagReaderSessionReadingAvailableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionReadingAvailable", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + tagReaderSessionReadingAvailableChannel.setMessageHandler { _, reply in + do { + let result = try api.tagReaderSessionReadingAvailable() + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + tagReaderSessionReadingAvailableChannel.setMessageHandler(nil) + } + let tagReaderSessionBeginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionBegin", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + tagReaderSessionBeginChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pollingOptionsArg = args[0] as! [String] + let alertMessageArg: String? = nilOrValue(args[1]) + let invalidateAfterFirstReadArg = args[2] as! Bool + do { + try api.tagReaderSessionBegin(pollingOptions: pollingOptionsArg, alertMessage: alertMessageArg, invalidateAfterFirstRead: invalidateAfterFirstReadArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + tagReaderSessionBeginChannel.setMessageHandler(nil) + } + let tagReaderSessionInvalidateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionInvalidate", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + tagReaderSessionInvalidateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let alertMessageArg: String? = nilOrValue(args[0]) + let errorMessageArg: String? = nilOrValue(args[1]) + do { + try api.tagReaderSessionInvalidate(alertMessage: alertMessageArg, errorMessage: errorMessageArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + tagReaderSessionInvalidateChannel.setMessageHandler(nil) + } + let tagReaderSessionRestartPollingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionRestartPolling", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + tagReaderSessionRestartPollingChannel.setMessageHandler { _, reply in + do { + try api.tagReaderSessionRestartPolling() + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + tagReaderSessionRestartPollingChannel.setMessageHandler(nil) + } + let tagReaderSessionSetAlertMessageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionSetAlertMessage", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + tagReaderSessionSetAlertMessageChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let alertMessageArg = args[0] as! String + do { + try api.tagReaderSessionSetAlertMessage(alertMessage: alertMessageArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + tagReaderSessionSetAlertMessageChannel.setMessageHandler(nil) + } + let vasReaderSessionReadingAvailableChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionReadingAvailable", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + vasReaderSessionReadingAvailableChannel.setMessageHandler { _, reply in + do { + let result = try api.vasReaderSessionReadingAvailable() + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + vasReaderSessionReadingAvailableChannel.setMessageHandler(nil) + } + let vasReaderSessionBeginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionBegin", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + vasReaderSessionBeginChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let configurationsArg = args[0] as! [PigeonNfcVasCommandConfiguration] + let alertMessageArg: String? = nilOrValue(args[1]) + do { + try api.vasReaderSessionBegin(configurations: configurationsArg, alertMessage: alertMessageArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + vasReaderSessionBeginChannel.setMessageHandler(nil) + } + let vasReaderSessionInvalidateChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionInvalidate", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + vasReaderSessionInvalidateChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let alertMessageArg: String? = nilOrValue(args[0]) + let errorMessageArg: String? = nilOrValue(args[1]) + do { + try api.vasReaderSessionInvalidate(alertMessage: alertMessageArg, errorMessage: errorMessageArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + vasReaderSessionInvalidateChannel.setMessageHandler(nil) + } + let vasReaderSessionSetAlertMessageChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionSetAlertMessage", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + vasReaderSessionSetAlertMessageChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let alertMessageArg = args[0] as! String + do { + try api.vasReaderSessionSetAlertMessage(alertMessage: alertMessageArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + vasReaderSessionSetAlertMessageChannel.setMessageHandler(nil) + } + let ndefQueryNDEFStatusChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefQueryNDEFStatus", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + ndefQueryNDEFStatusChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.ndefQueryNDEFStatus(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + ndefQueryNDEFStatusChannel.setMessageHandler(nil) + } + let ndefReadNDEFChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefReadNDEF", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + ndefReadNDEFChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.ndefReadNDEF(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + ndefReadNDEFChannel.setMessageHandler(nil) + } + let ndefWriteNDEFChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteNDEF", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + ndefWriteNDEFChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let messageArg = args[1] as! PigeonNdefMessage + api.ndefWriteNDEF(handle: handleArg, message: messageArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + ndefWriteNDEFChannel.setMessageHandler(nil) + } + let ndefWriteLockChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteLock", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + ndefWriteLockChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.ndefWriteLock(handle: handleArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + ndefWriteLockChannel.setMessageHandler(nil) + } + let feliCaPollingChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaPolling", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaPollingChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let systemCodeArg = args[1] as! FlutterStandardTypedData + let requestCodeArg = PigeonFeliCaPollingRequestCode(rawValue: args[2] as! Int)! + let timeSlotArg = PigeonFeliCaPollingTimeSlot(rawValue: args[3] as! Int)! + api.feliCaPolling(handle: handleArg, systemCode: systemCodeArg, requestCode: requestCodeArg, timeSlot: timeSlotArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaPollingChannel.setMessageHandler(nil) + } + let feliCaRequestServiceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestService", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaRequestServiceChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let nodeCodeListArg = args[1] as! [FlutterStandardTypedData] + api.feliCaRequestService(handle: handleArg, nodeCodeList: nodeCodeListArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaRequestServiceChannel.setMessageHandler(nil) + } + let feliCaRequestResponseChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestResponse", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaRequestResponseChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.feliCaRequestResponse(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaRequestResponseChannel.setMessageHandler(nil) + } + let feliCaReadWithoutEncryptionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaReadWithoutEncryption", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaReadWithoutEncryptionChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let serviceCodeListArg = args[1] as! [FlutterStandardTypedData] + let blockListArg = args[2] as! [FlutterStandardTypedData] + api.feliCaReadWithoutEncryption(handle: handleArg, serviceCodeList: serviceCodeListArg, blockList: blockListArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaReadWithoutEncryptionChannel.setMessageHandler(nil) + } + let feliCaWriteWithoutEncryptionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaWriteWithoutEncryption", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaWriteWithoutEncryptionChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let serviceCodeListArg = args[1] as! [FlutterStandardTypedData] + let blockListArg = args[2] as! [FlutterStandardTypedData] + let blockDataArg = args[3] as! [FlutterStandardTypedData] + api.feliCaWriteWithoutEncryption(handle: handleArg, serviceCodeList: serviceCodeListArg, blockList: blockListArg, blockData: blockDataArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaWriteWithoutEncryptionChannel.setMessageHandler(nil) + } + let feliCaRequestSystemCodeChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestSystemCode", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaRequestSystemCodeChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.feliCaRequestSystemCode(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaRequestSystemCodeChannel.setMessageHandler(nil) + } + let feliCaRequestServiceV2Channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestServiceV2", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaRequestServiceV2Channel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let nodeCodeListArg = args[1] as! [FlutterStandardTypedData] + api.feliCaRequestServiceV2(handle: handleArg, nodeCodeList: nodeCodeListArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaRequestServiceV2Channel.setMessageHandler(nil) + } + let feliCaRequestSpecificationVersionChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestSpecificationVersion", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaRequestSpecificationVersionChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.feliCaRequestSpecificationVersion(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaRequestSpecificationVersionChannel.setMessageHandler(nil) + } + let feliCaResetModeChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaResetMode", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaResetModeChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.feliCaResetMode(handle: handleArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaResetModeChannel.setMessageHandler(nil) + } + let feliCaSendFeliCaCommandChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaSendFeliCaCommand", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + feliCaSendFeliCaCommandChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let commandPacketArg = args[1] as! FlutterStandardTypedData + api.feliCaSendFeliCaCommand(handle: handleArg, commandPacket: commandPacketArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + feliCaSendFeliCaCommandChannel.setMessageHandler(nil) + } + let miFareSendMiFareCommandChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareCommand", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + miFareSendMiFareCommandChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let commandPacketArg = args[1] as! FlutterStandardTypedData + api.miFareSendMiFareCommand(handle: handleArg, commandPacket: commandPacketArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + miFareSendMiFareCommandChannel.setMessageHandler(nil) + } + let miFareSendMiFareISO7816CommandChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareISO7816Command", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + miFareSendMiFareISO7816CommandChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let apduArg = args[1] as! PigeonISO7816APDU + api.miFareSendMiFareISO7816Command(handle: handleArg, apdu: apduArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + miFareSendMiFareISO7816CommandChannel.setMessageHandler(nil) + } + let miFareSendMiFareISO7816CommandRawChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareISO7816CommandRaw", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + miFareSendMiFareISO7816CommandRawChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let dataArg = args[1] as! FlutterStandardTypedData + api.miFareSendMiFareISO7816CommandRaw(handle: handleArg, data: dataArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + miFareSendMiFareISO7816CommandRawChannel.setMessageHandler(nil) + } + let iso7816SendCommandChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso7816SendCommand", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso7816SendCommandChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let apduArg = args[1] as! PigeonISO7816APDU + api.iso7816SendCommand(handle: handleArg, apdu: apduArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso7816SendCommandChannel.setMessageHandler(nil) + } + let iso7816SendCommandRawChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso7816SendCommandRaw", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso7816SendCommandRawChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let dataArg = args[1] as! FlutterStandardTypedData + api.iso7816SendCommandRaw(handle: handleArg, data: dataArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso7816SendCommandRawChannel.setMessageHandler(nil) + } + let iso15693StayQuietChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693StayQuiet", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693StayQuietChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + api.iso15693StayQuiet(handle: handleArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693StayQuietChannel.setMessageHandler(nil) + } + let iso15693ReadSingleBlockChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ReadSingleBlock", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693ReadSingleBlockChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + api.iso15693ReadSingleBlock(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693ReadSingleBlockChannel.setMessageHandler(nil) + } + let iso15693WriteSingleBlockChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteSingleBlock", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693WriteSingleBlockChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + let dataBlockArg = args[3] as! FlutterStandardTypedData + api.iso15693WriteSingleBlock(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg, dataBlock: dataBlockArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693WriteSingleBlockChannel.setMessageHandler(nil) + } + let iso15693LockBlockChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockBlock", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693LockBlockChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + api.iso15693LockBlock(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693LockBlockChannel.setMessageHandler(nil) + } + let iso15693ReadMultipleBlocksChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ReadMultipleBlocks", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693ReadMultipleBlocksChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + let numberOfBlocksArg = args[3] is Int64 ? args[3] as! Int64 : Int64(args[3] as! Int32) + api.iso15693ReadMultipleBlocks(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg, numberOfBlocks: numberOfBlocksArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693ReadMultipleBlocksChannel.setMessageHandler(nil) + } + let iso15693WriteMultipleBlocksChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteMultipleBlocks", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693WriteMultipleBlocksChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + let numberOfBlocksArg = args[3] is Int64 ? args[3] as! Int64 : Int64(args[3] as! Int32) + let dataBlocksArg = args[4] as! [FlutterStandardTypedData] + api.iso15693WriteMultipleBlocks(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg, numberOfBlocks: numberOfBlocksArg, dataBlocks: dataBlocksArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693WriteMultipleBlocksChannel.setMessageHandler(nil) + } + let iso15693SelectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693Select", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693SelectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + api.iso15693Select(handle: handleArg, requestFlags: requestFlagsArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693SelectChannel.setMessageHandler(nil) + } + let iso15693ResetToReadyChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ResetToReady", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693ResetToReadyChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + api.iso15693ResetToReady(handle: handleArg, requestFlags: requestFlagsArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693ResetToReadyChannel.setMessageHandler(nil) + } + let iso15693WriteAfiChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteAfi", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693WriteAfiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let afiArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + api.iso15693WriteAfi(handle: handleArg, requestFlags: requestFlagsArg, afi: afiArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693WriteAfiChannel.setMessageHandler(nil) + } + let iso15693LockAfiChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockAfi", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693LockAfiChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + api.iso15693LockAfi(handle: handleArg, requestFlags: requestFlagsArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693LockAfiChannel.setMessageHandler(nil) + } + let iso15693WriteDsfIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteDsfId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693WriteDsfIdChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let dsfIdArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + api.iso15693WriteDsfId(handle: handleArg, requestFlags: requestFlagsArg, dsfId: dsfIdArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693WriteDsfIdChannel.setMessageHandler(nil) + } + let iso15693LockDsfIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockDsfId", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693LockDsfIdChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + api.iso15693LockDsfId(handle: handleArg, requestFlags: requestFlagsArg) { result in + switch result { + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693LockDsfIdChannel.setMessageHandler(nil) + } + let iso15693GetSystemInfoChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693GetSystemInfo", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693GetSystemInfoChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + api.iso15693GetSystemInfo(handle: handleArg, requestFlags: requestFlagsArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693GetSystemInfoChannel.setMessageHandler(nil) + } + let iso15693GetMultipleBlockSecurityStatusChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693GetMultipleBlockSecurityStatus", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693GetMultipleBlockSecurityStatusChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let blockNumberArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + let numberOfBlocksArg = args[3] is Int64 ? args[3] as! Int64 : Int64(args[3] as! Int32) + api.iso15693GetMultipleBlockSecurityStatus(handle: handleArg, requestFlags: requestFlagsArg, blockNumber: blockNumberArg, numberOfBlocks: numberOfBlocksArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693GetMultipleBlockSecurityStatusChannel.setMessageHandler(nil) + } + let iso15693CustomCommandChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693CustomCommand", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + iso15693CustomCommandChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let handleArg = args[0] as! String + let requestFlagsArg = args[1] as! [String] + let customCommandCodeArg = args[2] is Int64 ? args[2] as! Int64 : Int64(args[2] as! Int32) + let customRequestParametersArg = args[3] as! FlutterStandardTypedData + api.iso15693CustomCommand(handle: handleArg, requestFlags: requestFlagsArg, customCommandCode: customCommandCodeArg, customRequestParameters: customRequestParametersArg) { result in + switch result { + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) + } + } + } + } else { + iso15693CustomCommandChannel.setMessageHandler(nil) + } + } +} diff --git a/ios/Classes/SwiftNfcManagerPlugin.swift b/ios/Classes/SwiftNfcManagerPlugin.swift deleted file mode 100644 index c77b0a6..0000000 --- a/ios/Classes/SwiftNfcManagerPlugin.swift +++ /dev/null @@ -1,767 +0,0 @@ -import CoreNFC -import Flutter - -public class SwiftNfcManagerPlugin: NSObject, FlutterPlugin { - private let channel: FlutterMethodChannel - - private var _session: Any? - @available(iOS 13.0, *) - private var session: NFCTagReaderSession? { - get { return _session as? NFCTagReaderSession } - set { _session = newValue } - } - - private var _tags: Any? - @available(iOS 13.0, *) - private var tags: [String : NFCNDEFTag] { - get { return _tags as? [String : NFCNDEFTag] ?? [:] } - set { _tags = newValue } - } - - public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "plugins.flutter.io/nfc_manager", binaryMessenger: registrar.messenger()) - let instance = SwiftNfcManagerPlugin(channel) - registrar.addMethodCallDelegate(instance, channel: channel) - } - - private init(_ channel: FlutterMethodChannel) { - self.channel = channel - } - - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - guard #available(iOS 13.0, *) else { - result(FlutterError(code: "unavailable", message: "Only available in iOS 13.0 or newer", details: nil)) - return - } - - switch call.method { - case "Nfc#isAvailable": handleNfcIsAvailable(call.arguments, result: result) - case "Nfc#startSession": handleNfcStartSession(call.arguments as! [String : Any?], result: result) - case "Nfc#stopSession": handleNfcStopSession(call.arguments as! [String : Any?], result: result) - case "Nfc#disposeTag": handleNfcDisposeTag(call.arguments as! [String : Any?], result: result) - case "Ndef#read": handleNdefRead(call.arguments as! [String : Any?], result: result) - case "Ndef#write": handleNdefWrite(call.arguments as! [String : Any?], result: result) - case "Ndef#writeLock": handleNdefWriteLock(call.arguments as! [String : Any?], result: result) - case "FeliCa#polling": handleFeliCaPolling(call.arguments as! [String : Any?], result: result) - case "FeliCa#requestResponse": handleFeliCaRequestResponse(call.arguments as! [String : Any?], result: result) - case "FeliCa#requestSystemCode": handleFeliCaRequestSystemCode(call.arguments as! [String : Any?], result: result) - case "FeliCa#requestService": handleFeliCaRequestService(call.arguments as! [String : Any?], result: result) - case "FeliCa#requestServiceV2": handleFeliCaRequestServiceV2(call.arguments as! [String : Any?], result: result) - case "FeliCa#readWithoutEncryption": handleFeliCaReadWithoutEncryption(call.arguments as! [String : Any?], result: result) - case "FeliCa#writeWithoutEncryption": handleFeliCaWriteWithoutEncryption(call.arguments as! [String : Any?], result: result) - case "FeliCa#requestSpecificationVersion": handleFeliCaRequestSpecificationVersion(call.arguments as! [String : Any?], result: result) - case "FeliCa#resetMode": handleFeliCaResetMode(call.arguments as! [String : Any?], result: result) - case "FeliCa#sendFeliCaCommand": handleFeliCaSendFeliCaCommand(call.arguments as! [String : Any?], result: result) - case "Iso15693#readSingleBlock": handleIso15693ReadSingleBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#writeSingleBlock": handleIso15693WriteSingleBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#lockBlock": handleIso15693LockBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#readMultipleBlocks": handleIso15693ReadMultipleBlocks(call.arguments as! [String : Any?], result: result) - case "Iso15693#writeMultipleBlocks": handleIso15693WriteMultipleBlocks(call.arguments as! [String : Any?], result: result) - case "Iso15693#getMultipleBlockSecurityStatus": handleIso15693GetMultipleBlockSecurityStatus(call.arguments as! [String : Any?], result: result) - case "Iso15693#writeAfi": handleIso15693WriteAfi(call.arguments as! [String : Any?], result: result) - case "Iso15693#lockAfi": handleIso15693LockAfi(call.arguments as! [String : Any?], result: result) - case "Iso15693#writeDsfId": handleIso15693WriteDsfId(call.arguments as! [String : Any?], result: result) - case "Iso15693#lockDsfId": handleIso15693LockDsfId(call.arguments as! [String : Any?], result: result) - case "Iso15693#resetToReady": handleIso15693ResetToReady(call.arguments as! [String : Any?], result: result) - case "Iso15693#select": handleIso15693Select(call.arguments as! [String : Any?], result: result) - case "Iso15693#stayQuiet": handleIso15693StayQuiet(call.arguments as! [String : Any?], result: result) - case "Iso15693#extendedReadSingleBlock": handleIso15693ExtendedReadSingleBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#extendedWriteSingleBlock": handleIso15693ExtendedWriteSingleBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#extendedLockBlock": handleIso15693ExtendedLockBlock(call.arguments as! [String : Any?], result: result) - case "Iso15693#extendedReadMultipleBlocks": handleIso15693ExtendedReadMultipleBlocks(call.arguments as! [String : Any?], result: result) - case "Iso15693#getSystemInfo": handleIso15693GetSystemInfo(call.arguments as! [String : Any?], result: result) - case "Iso15693#customCommand": handleIso15693CustomCommand(call.arguments as! [String : Any?], result: result) - case "Iso7816#sendCommand": handleIso7816SendCommand(call.arguments as! [String : Any?], result: result) - case "Iso7816#sendCommandRaw": handleIso7816SendCommandRaw(call.arguments as! [String : Any?], result: result) - case "MiFare#sendMiFareCommand": handleMiFareSendMiFareCommand(call.arguments as! [String : Any?], result: result) - case "MiFare#sendMiFareIso7816Command": handleMiFareSendMiFareIso7816Command(call.arguments as! [String : Any?], result: result) - case "MiFare#sendMiFareIso7816CommandRaw": handleMiFareSendMiFareIso7816CommandRaw(call.arguments as! [String : Any?], result: result) - default: result(FlutterMethodNotImplemented) - } - } - - @available(iOS 13.0, *) - private func handleNfcIsAvailable(_ arguments: Any?, result: @escaping FlutterResult) { - result(NFCTagReaderSession.readingAvailable) - } - - @available(iOS 13.0, *) - private func handleNfcStartSession(_ arguments: [String : Any?], result: @escaping FlutterResult) { - session = NFCTagReaderSession(pollingOption: getPollingOption(arguments["pollingOptions"] as! [String]), delegate: self) - if let alertMessage = arguments["alertMessage"] as? String { session?.alertMessage = alertMessage } - session?.begin() - result(nil) - } - - @available(iOS 13.0, *) - private func handleNfcStopSession(_ arguments: [String : Any?], result: @escaping FlutterResult) { - guard let session = session else { - result(nil) - return - } - - if let errorMessage = arguments["errorMessage"] as? String { - session.invalidate(errorMessage: errorMessage) - self.session = nil - result(nil) - } - - if let alertMessage = arguments["alertMessage"] as? String { session.alertMessage = alertMessage } - session.invalidate() - self.session = nil - result(nil) - } - - @available(iOS 13.0, *) - private func handleNfcDisposeTag(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tags.removeValue(forKey: arguments["handle"] as! String) - result(nil) - } - - @available(iOS 13.0, *) - private func handleNdefRead(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCNDEFTag.self, arguments, result) { tag in - tag.readNDEF { message, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(message == nil ? nil : getNDEFMessageMap(message!)) - } - } - } - } - - @available(iOS 13.0, *) - private func handleNdefWrite(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCNDEFTag.self, arguments, result) { tag in - let message = getNDEFMessage(arguments["message"] as! [String : Any?]) - tag.writeNDEF(message) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleNdefWriteLock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCNDEFTag.self, arguments, result) { tag in - tag.writeLock { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaPolling(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let systemCode = (arguments["systemCode"] as! FlutterStandardTypedData).data - let requestCode = PollingRequestCode(rawValue: arguments["requestCode"] as! Int)! - let timeSlot = PollingTimeSlot(rawValue: arguments["timeSlot"] as! Int)! - tag.polling(systemCode: systemCode, requestCode: requestCode, timeSlot: timeSlot) { manufacturerParameter, requestData, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "manufacturerParameter": manufacturerParameter, - "requestData": requestData, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaRequestResponse(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - tag.requestResponse { mode, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(mode) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaRequestSystemCode(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - tag.requestSystemCode { systemCodeList, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(systemCodeList) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaRequestService(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let nodeCodeList = (arguments["nodeCodeList"] as! [FlutterStandardTypedData]).map { $0.data } - tag.requestService(nodeCodeList: nodeCodeList) { nodeKeyVersionList, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nodeKeyVersionList) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaRequestServiceV2(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let nodeCodeList = (arguments["nodeCodeList"] as! [FlutterStandardTypedData]).map { $0.data } - tag.requestServiceV2(nodeCodeList: nodeCodeList) { statusFlag1, statusFlag2, encryptionIdentifier, nodeKeyVersionListAes, nodeKeyVersionListDes, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "statusFlag1": statusFlag1, - "statusFlag2": statusFlag2, - "encryptionIdentifier": encryptionIdentifier.rawValue, - "nodeKeyVersionListAes": nodeKeyVersionListAes, - "nodeKeyVersionListDes": nodeKeyVersionListDes, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaReadWithoutEncryption(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let serviceCodeList = (arguments["serviceCodeList"] as! [FlutterStandardTypedData]).map { $0.data } - let blockList = (arguments["blockList"] as! [FlutterStandardTypedData]).map { $0.data } - tag.readWithoutEncryption(serviceCodeList: serviceCodeList, blockList: blockList) { statusFlag1, statusFlag2, blockData, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "statusFlag1": statusFlag1, - "statusFlag2": statusFlag2, - "blockData": blockData, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaWriteWithoutEncryption(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let serviceCodeList = (arguments["serviceCodeList"] as! [FlutterStandardTypedData]).map { $0.data } - let blockList = (arguments["blockList"] as! [FlutterStandardTypedData]).map { $0.data } - let blockData = (arguments["blockData"] as! [FlutterStandardTypedData]).map { $0.data } - tag.writeWithoutEncryption(serviceCodeList: serviceCodeList, blockList: blockList, blockData: blockData) { statusFlag1, statusFlag2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "statusFlag1": statusFlag1, - "statusFlag2": statusFlag2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaRequestSpecificationVersion(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - tag.requestSpecificationVersion { statusFlag1, statusFlag2, basicVersion, optionVersion, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "statusFlag1": statusFlag1, - "statusFlag2": statusFlag2, - "basicVersion": basicVersion, - "optionVersion": optionVersion, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaResetMode(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - tag.resetMode { statusFlag1, statusFlag2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "statusFlag1": statusFlag1, - "statusFlag2": statusFlag2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleFeliCaSendFeliCaCommand(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCFeliCaTag.self, arguments, result) { tag in - let commandPacket = (arguments["commandPacket"] as! FlutterStandardTypedData).data - tag.sendFeliCaCommand(commandPacket: commandPacket) { data, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(data) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ReadSingleBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! UInt8 - tag.readSingleBlock(requestFlags: requestFlags, blockNumber: blockNumber) { dataBlock, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(dataBlock) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693WriteSingleBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! UInt8 - let dataBlock = (arguments["dataBlock"] as! FlutterStandardTypedData).data - tag.writeSingleBlock(requestFlags: requestFlags, blockNumber: blockNumber, dataBlock: dataBlock) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693LockBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! UInt8 - tag.lockBlock(requestFlags: requestFlags, blockNumber: blockNumber) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ReadMultipleBlocks(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - let numberOfBlocks = arguments["numberOfBlocks"] as! Int - tag.readMultipleBlocks(requestFlags: requestFlags, blockRange: NSMakeRange(blockNumber, numberOfBlocks)) { dataBlocks, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(dataBlocks) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693WriteMultipleBlocks(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - let numberOfBlocks = arguments["numberOfBlocks"] as! Int - let dataBlocks = (arguments["dataBlocks"] as! [FlutterStandardTypedData]).map { $0.data } - tag.writeMultipleBlocks(requestFlags: requestFlags, blockRange: NSMakeRange(blockNumber, numberOfBlocks), dataBlocks: dataBlocks) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693GetMultipleBlockSecurityStatus(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - let numberOfBlocks = arguments["numberOfBlocks"] as! Int - tag.getMultipleBlockSecurityStatus(requestFlags: requestFlags, blockRange: NSMakeRange(blockNumber, numberOfBlocks)) { status, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(status) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693WriteAfi(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let afi = arguments["afi"] as! UInt8 - tag.writeAFI(requestFlags: requestFlags, afi: afi) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693LockAfi(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - tag.lockAFI(requestFlags: requestFlags) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693WriteDsfId(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let dsfId = arguments["dsfId"] as! UInt8 - tag.writeDSFID(requestFlags: requestFlags, dsfid: dsfId) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693LockDsfId(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - tag.lockDFSID(requestFlags: requestFlags) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ResetToReady(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - tag.resetToReady(requestFlags: requestFlags) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693Select(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - tag.select(requestFlags: requestFlags) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693StayQuiet(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - tag.stayQuiet { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ExtendedReadSingleBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - tag.extendedReadSingleBlock(requestFlags: requestFlags, blockNumber: blockNumber) { dataBlock, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(dataBlock) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ExtendedWriteSingleBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - let dataBlock = (arguments["dataBlock"] as! FlutterStandardTypedData).data - tag.extendedWriteSingleBlock(requestFlags: requestFlags, blockNumber: blockNumber, dataBlock: dataBlock) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ExtendedLockBlock(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - tag.extendedLockBlock(requestFlags: requestFlags, blockNumber: blockNumber) { error in - if let error = error { - result(getFlutterError(error)) - } else { - result(nil) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693ExtendedReadMultipleBlocks(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let blockNumber = arguments["blockNumber"] as! Int - let numberOfBlocks = arguments["numberOfBlocks"] as! Int - tag.extendedReadMultipleBlocks(requestFlags: requestFlags, blockRange: NSMakeRange(blockNumber, numberOfBlocks)) { dataBlocks, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(dataBlocks) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693GetSystemInfo(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - tag.getSystemInfo(requestFlags: requestFlags) { dataStorageFormatIdentifier, applicationFamilyIdentifier, blockSize, totalBlocks, icReference, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "dataStorageFormatIdentifier": dataStorageFormatIdentifier, - "applicationFamilyIdentifier": applicationFamilyIdentifier, - "blockSize": blockSize, - "totalBlocks": totalBlocks, - "icReference": icReference, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso15693CustomCommand(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO15693Tag.self, arguments, result) { tag in - let requestFlags = getRequestFlags(arguments["requestFlags"] as! [String]) - let customCommandCode = arguments["customCommandCode"] as! Int - let customRequestParameters = (arguments["customRequestParameters"] as! FlutterStandardTypedData).data - tag.customCommand(requestFlags: requestFlags, customCommandCode: customCommandCode, customRequestParameters: customRequestParameters) { data, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(data) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso7816SendCommand(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO7816Tag.self, arguments, result) { tag in - let apdu = NFCISO7816APDU( - instructionClass: arguments["instructionClass"] as! UInt8, - instructionCode: arguments["instructionCode"] as! UInt8, - p1Parameter: arguments["p1Parameter"] as! UInt8, - p2Parameter: arguments["p2Parameter"] as! UInt8, - data: (arguments["data"] as! FlutterStandardTypedData).data, - expectedResponseLength: arguments["expectedResponseLength"] as! Int - ) - tag.sendCommand(apdu: apdu) { payload, statusWord1, statusWord2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "payload": payload, - "statusWord1": statusWord1, - "statusWord2": statusWord2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleIso7816SendCommandRaw(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCISO7816Tag.self, arguments, result) { tag in - guard let apdu = NFCISO7816APDU(data: (arguments["data"] as! FlutterStandardTypedData).data) else { - result(FlutterError(code: "invalid_parameter", message: nil, details: nil)) - return - } - tag.sendCommand(apdu: apdu) { payload, statusWord1, statusWord2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "payload": payload, - "statusWord1": statusWord1, - "statusWord2": statusWord2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleMiFareSendMiFareCommand(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCMiFareTag.self, arguments, result) { tag in - let commandPacket = (arguments["commandPacket"] as! FlutterStandardTypedData).data - tag.sendMiFareCommand(commandPacket: commandPacket) { data, error in - if let error = error { - result(getFlutterError(error)) - } else { - result(data) - } - } - } - } - - @available(iOS 13.0, *) - private func handleMiFareSendMiFareIso7816Command(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCMiFareTag.self, arguments, result) { tag in - let apdu = NFCISO7816APDU( - instructionClass: arguments["instructionClass"] as! UInt8, - instructionCode: arguments["instructionCode"] as! UInt8, - p1Parameter: arguments["p1Parameter"] as! UInt8, - p2Parameter: arguments["p2Parameter"] as! UInt8, - data: (arguments["data"] as! FlutterStandardTypedData).data, - expectedResponseLength: arguments["expectedResponseLength"] as! Int - ) - tag.sendMiFareISO7816Command(apdu) { payload, statusWord1, statusWord2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "payload": payload, - "statusWord1": statusWord1, - "statusWord2": statusWord2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func handleMiFareSendMiFareIso7816CommandRaw(_ arguments: [String : Any?], result: @escaping FlutterResult) { - tagHandler(NFCMiFareTag.self, arguments, result) { tag in - guard let apdu = NFCISO7816APDU(data: (arguments["data"] as! FlutterStandardTypedData).data) else { - result(FlutterError(code: "invalid_parameter", message: nil, details: nil)) - return - } - tag.sendMiFareISO7816Command(apdu) { payload, statusWord1, statusWord2, error in - if let error = error { - result(getFlutterError(error)) - } else { - result([ - "payload": payload, - "statusWord1": statusWord1, - "statusWord2": statusWord2, - ]) - } - } - } - } - - @available(iOS 13.0, *) - private func tagHandler(_ dump: T.Type, _ arguments: [String : Any?], _ result: FlutterResult, callback: ((T) -> Void)) { - if let tag = tags[arguments["handle"] as! String] as? T { - callback(tag) - } else { - result(FlutterError(code: "invalid_parameter", message: "Tag is not found", details: nil)) - } - } -} - -@available(iOS 13.0, *) -extension SwiftNfcManagerPlugin: NFCTagReaderSessionDelegate { - public func tagReaderSessionDidBecomeActive(_ session: NFCTagReaderSession) { - // no op - } - - public func tagReaderSession(_ session: NFCTagReaderSession, didInvalidateWithError error: Error) { - channel.invokeMethod("onError", arguments: getErrorMap(error)) - } - - public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) { - let handle = NSUUID().uuidString - - session.connect(to: tags.first!) { error in - if let error = error { - // skip tag detection - print(error) - return - } - - getNFCTagMapAsync(tags.first!) { tag, data, error in - if let error = error { - // skip tag detection - print(error) - return - } - - self.tags[handle] = tag - self.channel.invokeMethod("onDiscovered", arguments: data.merging(["handle": handle]) { cur, _ in cur }) - } - } - } -} - diff --git a/ios/Classes/Translator.swift b/ios/Classes/Translator.swift deleted file mode 100644 index cf90a29..0000000 --- a/ios/Classes/Translator.swift +++ /dev/null @@ -1,161 +0,0 @@ -import CoreNFC - -@available(iOS 13.0, *) -func getPollingOption(_ arg: [String]) -> NFCTagReaderSession.PollingOption { - var option = NFCTagReaderSession.PollingOption() - if arg.contains("iso14443") { option.insert(NFCTagReaderSession.PollingOption.iso14443) } - if arg.contains("iso15693") { option.insert(NFCTagReaderSession.PollingOption.iso15693) } - if arg.contains("iso18092") { option.insert(NFCTagReaderSession.PollingOption.iso18092) } - return option -} - -@available(iOS 13.0, *) -func getRequestFlags(_ arg: [String]) -> RequestFlag { - var flag = RequestFlag() - if arg.contains("address") { flag.insert(RequestFlag.address) } - if arg.contains("dualSubCarriers") { flag.insert(RequestFlag.dualSubCarriers) } - if arg.contains("highDataRate") { flag.insert(RequestFlag.highDataRate) } - if arg.contains("option") { flag.insert(RequestFlag.option) } - if arg.contains("protocolExtension") { flag.insert(RequestFlag.protocolExtension) } - if arg.contains("select") { flag.insert(RequestFlag.select) } - return flag -} - -@available(iOS 11.0, *) -func getErrorTypeString(_ arg: NFCReaderError.Code) -> String? { - // TODO: add more cases - switch arg { - case .readerSessionInvalidationErrorSessionTimeout: return "sessionTimeout" - case .readerSessionInvalidationErrorSystemIsBusy: return "systemIsBusy" - case .readerSessionInvalidationErrorUserCanceled: return "userCanceled" - default: return nil - } -} - -@available(iOS 13.0, *) -func getNDEFMessage(_ arg: [String : Any?]) -> NFCNDEFMessage { - return NFCNDEFMessage(records: (arg["records"] as! Array<[String : Any?]>).map { - NFCNDEFPayload( - format: NFCTypeNameFormat(rawValue: $0["typeNameFormat"] as! UInt8)!, - type: ($0["type"] as! FlutterStandardTypedData).data, - identifier: ($0["identifier"] as! FlutterStandardTypedData).data, - payload: ($0["payload"] as! FlutterStandardTypedData).data - ) - }) -} - -@available(iOS 11.0, *) -func getNDEFMessageMap(_ arg: NFCNDEFMessage) -> [String : Any?] { - return ["records": arg.records.map { - [ - "typeNameFormat": $0.typeNameFormat.rawValue, - "type": $0.type, - "identifier": $0.identifier, - "payload": $0.payload, - ] - }] -} - -@available(iOS 13.0, *) -func getNFCTagMapAsync(_ arg: NFCTag, _ completionHandler: @escaping (NFCNDEFTag, [String:Any?], Error?) -> Void) { - switch (arg) { - case .feliCa(let tag): getNDEFTagMapAsync(tag) { data, error in completionHandler(tag, data, error) } - case .miFare(let tag): getNDEFTagMapAsync(tag) { data, error in completionHandler(tag, data, error) } - case .iso7816(let tag): getNDEFTagMapAsync(tag) { data, error in completionHandler(tag, data, error) } - case .iso15693(let tag): getNDEFTagMapAsync(tag) { data, error in completionHandler(tag, data, error) } - @unknown default: print("Unknown tag cannot be serialized") - } -} - -@available(iOS 13.0, *) -func getNDEFTagMapAsync(_ arg: NFCNDEFTag, _ completionHandler: @escaping ([String : Any?], Error?) -> Void) { - var data = getNDEFTagMap(arg) - - arg.queryNDEFStatus { status, capacity, error in - if let error = error { - completionHandler(data, error) - return - } - - if status == .notSupported { - completionHandler(data, nil) - return - } - - var ndefData: [String : Any?] = [ - "isWritable": (status == .readWrite), - "maxSize": capacity, - ] - - arg.readNDEF { message, _ in - - if let message = message { - ndefData["cachedMessage"] = getNDEFMessageMap(message) - } - - data["ndef"] = ndefData - - completionHandler(data, nil) - } - } -} - -@available(iOS 13.0, *) -func getNDEFTagMap(_ arg: NFCNDEFTag) -> [String : [String : Any?]] { - if let arg = arg as? NFCFeliCaTag { - return [ - "felica": [ - "currentIDm": arg.currentIDm, - "currentSystemCode": arg.currentSystemCode - ] - ] - } else if let arg = arg as? NFCISO15693Tag { - return [ - "iso15693": [ - "icManufacturerCode": arg.icManufacturerCode, - "icSerialNumber": arg.icSerialNumber, - "identifier": arg.identifier - ] - ] - } else if let arg = arg as? NFCISO7816Tag { - return [ - "iso7816": [ - "applicationData": arg.applicationData, - "historicalBytes": arg.historicalBytes, - "identifier": arg.identifier, - "initialSelectedAID": arg.initialSelectedAID, - "proprietaryApplicationDataCoding": arg.proprietaryApplicationDataCoding - ] - ] - } else if let arg = arg as? NFCMiFareTag { - return [ - "mifare": [ - "historicalBytes": arg.historicalBytes, - "identifier": arg.identifier, - "mifareFamily": arg.mifareFamily.rawValue - ] - ] - } else { - return [:] - } -} - -@available(iOS 11.0, *) -func getErrorMap(_ arg: Error) -> [String : Any?] { - if let arg = arg as? NFCReaderError { - return [ - "type": getErrorTypeString(arg.code), - "message": arg.localizedDescription, - "details": nil, - ] - } - return [ - "type": nil, - "message": arg.localizedDescription, - "details": nil, - ] -} - -func getFlutterError(_ arg: Error) -> FlutterError { - return FlutterError(code: "\((arg as NSError).code)", message:arg.localizedDescription, details: nil) -} diff --git a/ios/nfc_manager.podspec b/ios/nfc_manager.podspec index edd7106..6979007 100644 --- a/ios/nfc_manager.podspec +++ b/ios/nfc_manager.podspec @@ -15,7 +15,7 @@ A new Flutter plugin project. s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.platform = :ios, '9.0' + s.platform = :ios, '11.0' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } diff --git a/lib/nfc_manager.dart b/lib/nfc_manager.dart index b15d85a..0b980e3 100644 --- a/lib/nfc_manager.dart +++ b/lib/nfc_manager.dart @@ -1,2 +1 @@ export 'src/nfc_manager/nfc_manager.dart'; -export 'src/nfc_manager/nfc_ndef.dart'; diff --git a/lib/nfc_manager_android.dart b/lib/nfc_manager_android.dart new file mode 100644 index 0000000..82c96b8 --- /dev/null +++ b/lib/nfc_manager_android.dart @@ -0,0 +1,12 @@ +export 'src/nfc_manager_android/nfc_manager.dart'; +export 'src/nfc_manager_android/tags/iso_dep.dart'; +export 'src/nfc_manager_android/tags/mifare_classic.dart'; +export 'src/nfc_manager_android/tags/mifare_ultralight.dart'; +export 'src/nfc_manager_android/tags/ndef.dart'; +export 'src/nfc_manager_android/tags/ndef_formatable.dart'; +export 'src/nfc_manager_android/tags/nfc_a.dart'; +export 'src/nfc_manager_android/tags/nfc_b.dart'; +export 'src/nfc_manager_android/tags/nfc_barcode.dart'; +export 'src/nfc_manager_android/tags/nfc_f.dart'; +export 'src/nfc_manager_android/tags/nfc_v.dart'; +export 'src/nfc_manager_android/tags/tag.dart'; diff --git a/lib/nfc_manager_ios.dart b/lib/nfc_manager_ios.dart new file mode 100644 index 0000000..3e8a934 --- /dev/null +++ b/lib/nfc_manager_ios.dart @@ -0,0 +1,6 @@ +export 'src/nfc_manager_ios/nfc_manager.dart'; +export 'src/nfc_manager_ios/tags/felica.dart'; +export 'src/nfc_manager_ios/tags/iso15693.dart'; +export 'src/nfc_manager_ios/tags/iso7816.dart'; +export 'src/nfc_manager_ios/tags/mifare.dart'; +export 'src/nfc_manager_ios/tags/ndef.dart'; diff --git a/lib/platform_tags.dart b/lib/platform_tags.dart deleted file mode 100644 index 732ccaa..0000000 --- a/lib/platform_tags.dart +++ /dev/null @@ -1,12 +0,0 @@ -export 'src/platform_tags/felica.dart'; -export 'src/platform_tags/iso_dep.dart'; -export 'src/platform_tags/iso7816.dart'; -export 'src/platform_tags/iso15693.dart'; -export 'src/platform_tags/mifare.dart'; -export 'src/platform_tags/mifare_classic.dart'; -export 'src/platform_tags/mifare_ultralight.dart'; -export 'src/platform_tags/ndef_formatable.dart'; -export 'src/platform_tags/nfc_a.dart'; -export 'src/platform_tags/nfc_b.dart'; -export 'src/platform_tags/nfc_f.dart'; -export 'src/platform_tags/nfc_v.dart'; diff --git a/lib/src/channel.dart b/lib/src/channel.dart deleted file mode 100644 index f39efde..0000000 --- a/lib/src/channel.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:flutter/services.dart'; - -const MethodChannel channel = MethodChannel('plugins.flutter.io/nfc_manager'); diff --git a/lib/src/nfc_manager/nfc_manager.dart b/lib/src/nfc_manager/nfc_manager.dart index 819ec20..e710a41 100644 --- a/lib/src/nfc_manager/nfc_manager.dart +++ b/lib/src/nfc_manager/nfc_manager.dart @@ -1,193 +1,103 @@ -import 'package:flutter/services.dart'; - -import '../channel.dart'; -import '../translator.dart'; - -/// Signature for `NfcManager.startSession` onDiscovered callback. -typedef NfcTagCallback = Future Function(NfcTag tag); - -/// Signature for `NfcManager.startSession` onError callback. -typedef NfcErrorCallback = Future Function(NfcError error); +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager_android/nfc_manager_platform.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/nfc_manager_platform.dart'; /// The entry point for accessing the NFC session. -class NfcManager { - NfcManager._() { - channel.setMethodCallHandler(_handleMethodCall); - } +abstract class NfcManager { static NfcManager? _instance; - /// A Singleton instance of NfcManager. - static NfcManager get instance => _instance ??= NfcManager._(); - - // _onDiscovered - NfcTagCallback? _onDiscovered; - - // _onError - NfcErrorCallback? _onError; - - /// Checks whether the NFC features are available. - Future isAvailable() async { - return channel.invokeMethod('Nfc#isAvailable').then((value) => value!); + /// The instance of the [NfcManager] to use. + static NfcManager get instance { + return _instance ??= switch (defaultTargetPlatform) { + TargetPlatform.android => NfcManagerAndroidPlatform(), + TargetPlatform.iOS => NfcManagerIOSPlatform(), + _ => throw 'unsupported platform: $defaultTargetPlatform', + }; } - /// Start the session and register callbacks for tag discovery. + /// Checks whether the NFC session is available. + Future isAvailable(); + + /// Starts the session and registers callbacks for tag discovery. /// - /// This uses the NFCTagReaderSession (on iOS) or NfcAdapter#enableReaderMode (on Android). - /// Requires iOS 13.0 or Android API 19, or later. + /// Use [pollingOptions] to specify which tag types to discover. /// - /// `onDiscovered` is called whenever the tag is discovered. + /// [onDiscovered] is called when the session discovers the tag. /// - /// `pollingOptions` is used to specify the type of tags to be discovered. All types by default. + /// (iOS only) [alertMessageIOS] is used to display the message on popup + /// shown when the session is started. /// - /// (iOS only) `alertMessage` is used to display the message on the popup shown when the session is started. + /// (iOS only) [invalidateAfterFirstReadIOS] is used to specify whether the + /// session should be invalidated after the first tag discovery. Default is true. /// - /// (iOS only) `onError` is called when the session is stopped for some reason after the session has started. + /// (iOS only) [onSessionErrorIOS] is called when the session is invalidated for + /// some reason after the session has started. Future startSession({ - required NfcTagCallback onDiscovered, - Set? pollingOptions, - String? alertMessage, - NfcErrorCallback? onError, - }) async { - _onDiscovered = onDiscovered; - _onError = onError; - pollingOptions ??= NfcPollingOption.values.toSet(); - return channel.invokeMethod('Nfc#startSession', { - 'pollingOptions': - pollingOptions.map((e) => $NfcPollingOptionTable[e]).toList(), - 'alertMessage': alertMessage, - }); - } + required Set pollingOptions, + required void Function(NfcTag) onDiscovered, + String? alertMessageIOS, + bool invalidateAfterFirstReadIOS = true, + void Function(NfcReaderSessionErrorIOS)? onSessionErrorIOS, + }); - /// Stop the session and unregister callbacks. - /// - /// This uses the NFCTagReaderSession (on iOS) or NfcAdapter#disableReaderMode (on Android). - /// Requires iOS 13.0 or Android API 19, or later. + /// Stops the session and unregisters callbacks. /// - /// (iOS only) `alertMessage` and `errorMessage` are used to display the success or error message on the popup. - /// if both are used, `errorMessage` is used. + /// (iOS only) [alertMessageIOS] and [errorMessageIOS] are used to display + /// success or error message on the popup. If both are used, [errorMessageIOS] is used. Future stopSession({ - String? alertMessage, - String? errorMessage, - }) async { - _onDiscovered = null; - _onError = null; - return channel.invokeMethod('Nfc#stopSession', { - 'alertMessage': alertMessage, - 'errorMessage': errorMessage, - }); - } - - // _disposeTag - Future _disposeTag(String handle) async { - return channel.invokeMethod('Nfc#disposeTag', { - 'handle': handle, - }); - } - - // _handleMethodCall - Future _handleMethodCall(MethodCall call) async { - switch (call.method) { - case 'onDiscovered': - _handleOnDiscovered(call); - break; - case 'onError': - _handleOnError(call); - break; - default: - throw ('Not implemented: ${call.method}'); - } - } - - // _handleOnDiscovered - void _handleOnDiscovered(MethodCall call) async { - final tag = $GetNfcTag(Map.from(call.arguments)); - await _onDiscovered?.call(tag); - await _disposeTag(tag.handle); - } - - // _handleOnError - void _handleOnError(MethodCall call) async { - final error = $GetNfcError(Map.from(call.arguments)); - await _onError?.call(error); - } + String? alertMessageIOS, + String? errorMessageIOS, + }); } -/// The class represents the tag discovered by the session. -class NfcTag { - /// Constructs an instance with the given values for testing. +/// The class that represents the tag discovered by the session. +/// +/// When the session discovers a tag, it returns an instance of this class. Use +/// this generic instance to instantiate a specific tag class and retrieve +/// tag-specific operations. +/// +/// ```dart +/// import 'package:nfc_manager/nfc_manager.dart'; +/// import 'package:nfc_manager_ndef/nfc_manager_ndef.dart'; +/// +/// +/// NfcManager.instance.startSession( +/// pollingOptions: ..., +/// onDiscovered: (NfcTag tag) async { +/// final ndef = Ndef.from(tag); +/// if (ndef == null) { +/// print('The tag is not compatible with NDEF.'); +/// return; +/// } +/// // Do something with NDEF instance... +/// }, +/// ); +/// ``` +final class NfcTag { + /// Constructs an instance of this class for given data for testing. /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the onDiscovered callback of `NfcManager#startSession` are valid. - const NfcTag({ - required this.handle, - required this.data, - }); - - /// The value used by this plugin internally. - final String handle; + /// The instances constructed by this way are not valid in the production + /// environment. Only instances obtained from the `onDiscovered` callback of + /// the session are valid. + @visibleForTesting + const NfcTag({required this.data}); /// The raw values about this tag obtained from the native platform. /// - /// Don't use this values directly. Instead, access it via the platform_tags classes. For example: - /// - /// ```dart - /// Ndef? ndef = Ndef.from(tag); - /// if (ndef == null) { - /// print('Tag is not compatible with NDEF'); - /// return; - /// } - /// // Do something with an Ndef instance. - /// ``` - final Map data; -} - -/// The class represents the error when the session is stopped. -class NfcError { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the onError callback of `NfcManager#startSession` are valid. - const NfcError({ - required this.type, - required this.message, - this.details, - }); - - /// The error type. - final NfcErrorType type; - - /// The error message. - final String message; - - /// The error details information. - final dynamic details; + /// Don't use this values directly. Instead, access it via the specific tag classes. + @protected + final Object data; } -/// Represents the type of tag to be discovered by the session. -/// -/// Typically used with `NfcManager#startSession` function. +/// The values that specify which tag types to discover when calling [NfcManager.startSession]. enum NfcPollingOption { - /// `iso14443` on iOS, and `FLAG_READER_A` and `FLAG_READER_B` on Android. + /// The value indicating that the session will discover ISO 14443 tags. iso14443, - /// `iso15693` on iOS, and `FLAG_READER_V` on Android. + /// The value indicating that the session will discover ISO 15693 tags. iso15693, - /// `iso18092` on iOS, and `FLAG_READER_F` on Android. + /// The value indicating that the session will discover ISO 18092 tags. iso18092, } - -/// Represents the type of error that occurs when the session has stopped. -enum NfcErrorType { - /// The session timed out. - sessionTimeout, - - /// The session failed because the system is busy. - systemIsBusy, - - /// The user canceled the session. - userCanceled, - - /// The session failed because the unexpected error has occurred. - unknown, -} diff --git a/lib/src/nfc_manager/nfc_ndef.dart b/lib/src/nfc_manager/nfc_ndef.dart deleted file mode 100644 index ff2b7ac..0000000 --- a/lib/src/nfc_manager/nfc_ndef.dart +++ /dev/null @@ -1,297 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import '../channel.dart'; -import '../translator.dart'; -import './nfc_manager.dart'; - -/// The class provides access to NDEF operations on the tag. -/// -/// Acquire `Ndef` instance using `Ndef.from`. -class Ndef { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `Ndef.from` are valid. - const Ndef({ - required NfcTag tag, - required this.isWritable, - required this.maxSize, - required this.cachedMessage, - required this.additionalData, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Ndef#isWritable on Android, NFCNDEFTag#queryStatus on iOS. - final bool isWritable; - - /// The value from Ndef#maxSize on Android, NFCNDEFTag#queryStatus on iOS. - final int maxSize; - - /// The value from Ndef#cachedNdefMessage on Android, NFCNDEFTag#read on iOS. - /// - /// This value is cached at tag discovery. - final NdefMessage? cachedMessage; - - /// The value represents some additional data. - final Map additionalData; - - /// Get an instance of `Ndef` for the given tag. - /// - /// Returns null if the tag is not compatible with NDEF. - static Ndef? from(NfcTag tag) => $GetNdef(tag); - - /// Read the current NDEF message on this tag. - Future read() async { - return channel.invokeMethod('Ndef#read', { - 'handle': _tag.handle, - }).then((value) => $GetNdefMessage(Map.from(value))); - } - - /// Write the NDEF message on this tag. - Future write(NdefMessage message) async { - return channel.invokeMethod('Ndef#write', { - 'handle': _tag.handle, - 'message': $GetNdefMessageMap(message), - }); - } - - /// Change the NDEF status to read-only. - /// - /// This is a permanent action that you cannot undo. After locking the tag, you can no longer write data to it. - Future writeLock() async { - return channel.invokeMethod('Ndef#writeLock', { - 'handle': _tag.handle, - }); - } -} - -/// The class represents the immutable NDEF message. -class NdefMessage { - /// Constructs an instance with given records. - const NdefMessage(this.records); - - /// Records. - final List records; - - /// The length in bytes of the NDEF message when stored on the tag. - int get byteLength => records.isEmpty - ? 0 - : records.map((e) => e.byteLength).reduce((a, b) => a + b); -} - -/// The class represents the immutable NDEF record. -class NdefRecord { - /// URI_PREFIX_LIST - static const URI_PREFIX_LIST = [ - '', - 'http://www.', - 'https://www.', - 'http://', - 'https://', - 'tel:', - 'mailto:', - 'ftp://anonymous:anonymous@', - 'ftp://ftp.', - 'ftps://', - 'sftp://', - 'smb://', - 'nfs://', - 'ftp://', - 'dav://', - 'news:', - 'telnet://', - 'imap:', - 'rtsp://', - 'urn:', - 'pop:', - 'sip:', - 'sips:', - 'tftp:', - 'btspp://', - 'btl2cap://', - 'btgoep://', - 'tcpobex://', - 'irdaobex://', - 'file://', - 'urn:epc:id:', - 'urn:epc:tag:', - 'urn:epc:pat:', - 'urn:epc:raw:', - 'urn:epc:', - 'urn:nfc:', - ]; - - // NdefRecord - const NdefRecord._({ - required this.typeNameFormat, - required this.type, - required this.identifier, - required this.payload, - }); - - /// Type Name Format. - final NdefTypeNameFormat typeNameFormat; - - /// Type. - final Uint8List type; - - /// Identifier. - final Uint8List identifier; - - /// Payload. - final Uint8List payload; - - /// The length in bytes of the NDEF record when stored on the tag. - int get byteLength { - var length = 3 + type.length + identifier.length + payload.length; - - // not short record - if (payload.length > 255) length += 3; - - // id length - if (typeNameFormat == NdefTypeNameFormat.empty || identifier.length > 0) - length += 1; - - return length; - } - - /// Constructs an instance with the given values. - /// - /// Recommend to use other factory constructors such as `createText` or `createUri` where possible, - /// since they will ensure that the records are formatted correctly according to the NDEF specification. - factory NdefRecord({ - required NdefTypeNameFormat typeNameFormat, - required Uint8List type, - required Uint8List identifier, - required Uint8List payload, - }) { - _validateFormat(typeNameFormat, type, identifier, payload); - return NdefRecord._( - typeNameFormat: typeNameFormat, - type: type, - identifier: identifier, - payload: payload, - ); - } - - /// Constructs an instance containing UTF-8 text. - /// - /// Can specify the `languageCode` for the given text, `en` by default. - factory NdefRecord.createText(String text, {String languageCode = 'en'}) { - final languageCodeBytes = ascii.encode(languageCode); - if (languageCodeBytes.length >= 64) throw ('languageCode is too long'); - - return NdefRecord( - typeNameFormat: NdefTypeNameFormat.nfcWellknown, - type: Uint8List.fromList([0x54]), - identifier: Uint8List.fromList([]), - payload: Uint8List.fromList( - [languageCodeBytes.length] + languageCodeBytes + utf8.encode(text), - ), - ); - } - - /// Constructs an instance containing URI. - factory NdefRecord.createUri(Uri uri) { - final uriString = uri.normalizePath().toString(); - if (uriString.isEmpty) throw ('uri is empty'); - - int prefixIndex = - URI_PREFIX_LIST.indexWhere((e) => uriString.startsWith(e), 1); - if (prefixIndex < 0) prefixIndex = 0; - - return NdefRecord( - typeNameFormat: NdefTypeNameFormat.nfcWellknown, - type: Uint8List.fromList([0x55]), - identifier: Uint8List.fromList([]), - payload: Uint8List.fromList( - [prefixIndex] + - utf8.encode( - uriString.substring(URI_PREFIX_LIST[prefixIndex].length)), - )); - } - - /// Constructs an instance containing media data as defined by RFC 2046. - factory NdefRecord.createMime(String type, Uint8List data) { - type = type.toLowerCase().trim().split(';').first; - if (type.isEmpty) throw ('type is empty'); - - final slashIndex = type.indexOf('/'); - if (slashIndex == 0) throw ('type must have mojor type'); - if (slashIndex == type.length - 1) throw ('type must have minor type'); - - return NdefRecord( - typeNameFormat: NdefTypeNameFormat.media, - type: ascii.encode(type), - identifier: Uint8List.fromList([]), - payload: data, - ); - } - - /// Constructs an instance containing external (application-specific) data. - factory NdefRecord.createExternal( - String domain, String type, Uint8List data) { - domain = domain.trim().toLowerCase(); - type = type.trim().toLowerCase(); - if (domain.isEmpty) throw ('domain is empty'); - if (type.isEmpty) throw ('type is empty'); - - return NdefRecord( - typeNameFormat: NdefTypeNameFormat.nfcExternal, - type: Uint8List.fromList( - utf8.encode(domain) + ':'.codeUnits + utf8.encode(type)), - identifier: Uint8List.fromList([]), - payload: data, - ); - } - - // _validateFormat - static void _validateFormat(NdefTypeNameFormat format, Uint8List type, - Uint8List identifier, Uint8List payload) { - switch (format) { - case NdefTypeNameFormat.empty: - if (type.isNotEmpty || identifier.isNotEmpty || payload.isNotEmpty) - throw ('unexpected data in EMPTY record'); - break; - case NdefTypeNameFormat.nfcWellknown: - case NdefTypeNameFormat.media: - case NdefTypeNameFormat.absoluteUri: - case NdefTypeNameFormat.nfcExternal: - break; - case NdefTypeNameFormat.unknown: - if (type.isNotEmpty) throw ('unexpected type field in UNKNOWN record'); - break; - case NdefTypeNameFormat.unchanged: - throw ('unexpected UNCHANGED in first chunk or logical record'); - default: - throw ('unexpected format: $format'); - } - } -} - -/// Represents the NDEF Type-Name-Format as defined by the NFC specification. -enum NdefTypeNameFormat { - /// The record contains no data. - empty, - - /// The record contains well-known NFC record type data. - nfcWellknown, - - /// The record contains media data as defined by RFC 2046. - media, - - /// The record contains uniform resource identifier. - absoluteUri, - - /// The record contains NFC external type data. - nfcExternal, - - /// The record type is unknown. - unknown, - - /// The record is part of a series of records containing chunked data. - unchanged, -} diff --git a/lib/src/nfc_manager_android/nfc_manager.dart b/lib/src/nfc_manager_android/nfc_manager.dart new file mode 100644 index 0000000..8d27833 --- /dev/null +++ b/lib/src/nfc_manager_android/nfc_manager.dart @@ -0,0 +1,111 @@ +import 'dart:async'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; + +/// The entry point for accessing the NFC session on Android. +class NfcManagerAndroid { + NfcManagerAndroid._() { + _NfcManagerAndroidFlutterApi(this); + } + + /// The instance of the [NfcManagerAndroid] to use. + static NfcManagerAndroid get instance => _instance ??= NfcManagerAndroid._(); + static NfcManagerAndroid? _instance; + + // ignore: close_sinks + final StreamController _onStateChanged = StreamController.broadcast(); + + /// DOC: + Stream get onStateChanged => _onStateChanged.stream; + + void Function(NfcTag)? _onTagDiscovered; + + /// DOC: + Future isEnabled() { + return hostApi.nfcAdapterIsEnabled(); + } + + /// DOC: + Future isSecureNfcEnabled() { + return hostApi.nfcAdapterIsSecureNfcEnabled(); + } + + /// DOC: + Future isSecureNfcSupported() { + return hostApi.nfcAdapterIsSecureNfcSupported(); + } + + /// DOC: + Future enableReaderMode({ + required Set flags, + required void Function(NfcTag) onTagDiscovered, + }) { + _onTagDiscovered = onTagDiscovered; + return hostApi.nfcAdapterEnableReaderMode( + flags: flags.map((e) => e.name).toList(), + ); + } + + /// DOC: + Future disableReaderMode() { + _onTagDiscovered = null; + return hostApi.nfcAdapterDisableReaderMode(); + } + + /// DOC: + Future enableForegroundDispatch() { + return hostApi.nfcAdapterEnableForegroundDispatch(); + } + + /// DOC: + Future disableForegroundDispatch() { + return hostApi.nfcAdapterDisableForegroundDispatch(); + } +} + +class _NfcManagerAndroidFlutterApi implements PigeonFlutterApi { + _NfcManagerAndroidFlutterApi(this._instance) { + PigeonFlutterApi.setup(this); + } + + final NfcManagerAndroid _instance; + + @override + void onAdapterStateChanged(int state) { + _instance._onStateChanged.sink.add(state); + } + + @override + void onTagDiscovered(PigeonTag tag) { + _instance._onTagDiscovered?.call( + // ignore: invalid_use_of_visible_for_testing_member + NfcTag(data: tag), + ); + } +} + +/// DOC: +enum NfcReaderFlagAndroid { + /// DOC: + nfcA, + + /// DOC: + nfcB, + + /// DOC: + nfcBarcode, + + /// DOC: + nfcF, + + /// DOC: + nfcV, + + /// DOC: + noPlatformSounds, + + /// DOC: + skipNdefCheck, +} diff --git a/lib/src/nfc_manager_android/nfc_manager_platform.dart b/lib/src/nfc_manager_android/nfc_manager_platform.dart new file mode 100644 index 0000000..55bc26f --- /dev/null +++ b/lib/src/nfc_manager_android/nfc_manager_platform.dart @@ -0,0 +1,40 @@ +import 'dart:async'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/nfc_manager.dart'; + +class NfcManagerAndroidPlatform implements NfcManager { + @override + Future isAvailable() { + return NfcManagerAndroid.instance.isEnabled(); + } + + @override + Future startSession({ + required Set pollingOptions, + required void Function(NfcTag) onDiscovered, + String? alertMessageIOS, + bool invalidateAfterFirstReadIOS = true, + void Function(NfcReaderSessionErrorIOS)? onSessionErrorIOS, + }) { + return NfcManagerAndroid.instance.enableReaderMode( + flags: { + if (pollingOptions.contains(NfcPollingOption.iso14443)) ...{ + NfcReaderFlagAndroid.nfcA, + NfcReaderFlagAndroid.nfcB + }, + if (pollingOptions.contains(NfcPollingOption.iso15693)) + NfcReaderFlagAndroid.nfcV, + if (pollingOptions.contains(NfcPollingOption.iso18092)) + NfcReaderFlagAndroid.nfcF, + }, + onTagDiscovered: onDiscovered, + ); + } + + @override + Future stopSession({String? alertMessageIOS, String? errorMessageIOS}) { + return NfcManagerAndroid.instance.disableReaderMode(); + } +} diff --git a/lib/src/nfc_manager_android/pigeon.dart b/lib/src/nfc_manager_android/pigeon.dart new file mode 100644 index 0000000..c781569 --- /dev/null +++ b/lib/src/nfc_manager_android/pigeon.dart @@ -0,0 +1,3 @@ +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; + +final hostApi = PigeonHostApi(); diff --git a/lib/src/nfc_manager_android/pigeon.g.dart b/lib/src/nfc_manager_android/pigeon.g.dart new file mode 100644 index 0000000..1911c22 --- /dev/null +++ b/lib/src/nfc_manager_android/pigeon.g.dart @@ -0,0 +1,2033 @@ +// Autogenerated from Pigeon (v15.0.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers + +import 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; + +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/services.dart'; + +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + +enum PigeonTypeNameFormat { + empty, + wellKnown, + media, + absoluteUri, + external, + unknown, + unchanged, +} + +enum PigeonMifareClassicType { + classic, + plus, + pro, + unknown, +} + +enum PigeonMifareUltralightType { + ultralight, + ultralightC, + unknown, +} + +class PigeonTag { + PigeonTag({ + required this.handle, + required this.id, + required this.techList, + this.ndef, + this.nfcA, + this.nfcB, + this.nfcF, + this.nfcV, + this.isoDep, + this.mifareClassic, + this.mifareUltralight, + this.ndefFormatable, + this.nfcBarcode, + }); + + String handle; + + Uint8List id; + + List techList; + + PigeonNdef? ndef; + + PigeonNfcA? nfcA; + + PigeonNfcB? nfcB; + + PigeonNfcF? nfcF; + + PigeonNfcV? nfcV; + + PigeonIsoDep? isoDep; + + PigeonMifareClassic? mifareClassic; + + PigeonMifareUltralight? mifareUltralight; + + String? ndefFormatable; + + PigeonNfcBarcode? nfcBarcode; + + Object encode() { + return [ + handle, + id, + techList, + ndef?.encode(), + nfcA?.encode(), + nfcB?.encode(), + nfcF?.encode(), + nfcV?.encode(), + isoDep?.encode(), + mifareClassic?.encode(), + mifareUltralight?.encode(), + ndefFormatable, + nfcBarcode?.encode(), + ]; + } + + static PigeonTag decode(Object result) { + result as List; + return PigeonTag( + handle: result[0]! as String, + id: result[1]! as Uint8List, + techList: (result[2] as List?)!.cast(), + ndef: result[3] != null + ? PigeonNdef.decode(result[3]! as List) + : null, + nfcA: result[4] != null + ? PigeonNfcA.decode(result[4]! as List) + : null, + nfcB: result[5] != null + ? PigeonNfcB.decode(result[5]! as List) + : null, + nfcF: result[6] != null + ? PigeonNfcF.decode(result[6]! as List) + : null, + nfcV: result[7] != null + ? PigeonNfcV.decode(result[7]! as List) + : null, + isoDep: result[8] != null + ? PigeonIsoDep.decode(result[8]! as List) + : null, + mifareClassic: result[9] != null + ? PigeonMifareClassic.decode(result[9]! as List) + : null, + mifareUltralight: result[10] != null + ? PigeonMifareUltralight.decode(result[10]! as List) + : null, + ndefFormatable: result[11] as String?, + nfcBarcode: result[12] != null + ? PigeonNfcBarcode.decode(result[12]! as List) + : null, + ); + } +} + +class PigeonNdef { + PigeonNdef({ + required this.type, + required this.canMakeReadOnly, + required this.isWritable, + required this.maxSize, + this.cachedNdefMessage, + }); + + String type; + + bool canMakeReadOnly; + + bool isWritable; + + int maxSize; + + PigeonNdefMessage? cachedNdefMessage; + + Object encode() { + return [ + type, + canMakeReadOnly, + isWritable, + maxSize, + cachedNdefMessage?.encode(), + ]; + } + + static PigeonNdef decode(Object result) { + result as List; + return PigeonNdef( + type: result[0]! as String, + canMakeReadOnly: result[1]! as bool, + isWritable: result[2]! as bool, + maxSize: result[3]! as int, + cachedNdefMessage: result[4] != null + ? PigeonNdefMessage.decode(result[4]! as List) + : null, + ); + } +} + +class PigeonNfcA { + PigeonNfcA({ + required this.atqa, + required this.sak, + }); + + Uint8List atqa; + + int sak; + + Object encode() { + return [ + atqa, + sak, + ]; + } + + static PigeonNfcA decode(Object result) { + result as List; + return PigeonNfcA( + atqa: result[0]! as Uint8List, + sak: result[1]! as int, + ); + } +} + +class PigeonNfcB { + PigeonNfcB({ + required this.applicationData, + required this.protocolInfo, + }); + + Uint8List applicationData; + + Uint8List protocolInfo; + + Object encode() { + return [ + applicationData, + protocolInfo, + ]; + } + + static PigeonNfcB decode(Object result) { + result as List; + return PigeonNfcB( + applicationData: result[0]! as Uint8List, + protocolInfo: result[1]! as Uint8List, + ); + } +} + +class PigeonNfcF { + PigeonNfcF({ + required this.manufacturer, + required this.systemCode, + }); + + Uint8List manufacturer; + + Uint8List systemCode; + + Object encode() { + return [ + manufacturer, + systemCode, + ]; + } + + static PigeonNfcF decode(Object result) { + result as List; + return PigeonNfcF( + manufacturer: result[0]! as Uint8List, + systemCode: result[1]! as Uint8List, + ); + } +} + +class PigeonNfcV { + PigeonNfcV({ + required this.dsfId, + required this.responseFlags, + }); + + int dsfId; + + int responseFlags; + + Object encode() { + return [ + dsfId, + responseFlags, + ]; + } + + static PigeonNfcV decode(Object result) { + result as List; + return PigeonNfcV( + dsfId: result[0]! as int, + responseFlags: result[1]! as int, + ); + } +} + +class PigeonIsoDep { + PigeonIsoDep({ + this.hiLayerResponse, + this.historicalBytes, + required this.isExtendedLengthApduSupported, + }); + + Uint8List? hiLayerResponse; + + Uint8List? historicalBytes; + + bool isExtendedLengthApduSupported; + + Object encode() { + return [ + hiLayerResponse, + historicalBytes, + isExtendedLengthApduSupported, + ]; + } + + static PigeonIsoDep decode(Object result) { + result as List; + return PigeonIsoDep( + hiLayerResponse: result[0] as Uint8List?, + historicalBytes: result[1] as Uint8List?, + isExtendedLengthApduSupported: result[2]! as bool, + ); + } +} + +class PigeonMifareClassic { + PigeonMifareClassic({ + required this.type, + required this.blockCount, + required this.sectorCount, + required this.size, + }); + + PigeonMifareClassicType type; + + int blockCount; + + int sectorCount; + + int size; + + Object encode() { + return [ + type.index, + blockCount, + sectorCount, + size, + ]; + } + + static PigeonMifareClassic decode(Object result) { + result as List; + return PigeonMifareClassic( + type: PigeonMifareClassicType.values[result[0]! as int], + blockCount: result[1]! as int, + sectorCount: result[2]! as int, + size: result[3]! as int, + ); + } +} + +class PigeonMifareUltralight { + PigeonMifareUltralight({ + required this.type, + }); + + PigeonMifareUltralightType type; + + Object encode() { + return [ + type.index, + ]; + } + + static PigeonMifareUltralight decode(Object result) { + result as List; + return PigeonMifareUltralight( + type: PigeonMifareUltralightType.values[result[0]! as int], + ); + } +} + +class PigeonNfcBarcode { + PigeonNfcBarcode({ + required this.type, + required this.barcode, + }); + + int type; + + Uint8List barcode; + + Object encode() { + return [ + type, + barcode, + ]; + } + + static PigeonNfcBarcode decode(Object result) { + result as List; + return PigeonNfcBarcode( + type: result[0]! as int, + barcode: result[1]! as Uint8List, + ); + } +} + +class PigeonNdefMessage { + PigeonNdefMessage({ + required this.records, + }); + + List records; + + Object encode() { + return [ + records, + ]; + } + + static PigeonNdefMessage decode(Object result) { + result as List; + return PigeonNdefMessage( + records: (result[0] as List?)!.cast(), + ); + } +} + +class PigeonNdefRecord { + PigeonNdefRecord({ + required this.tnf, + required this.type, + required this.id, + required this.payload, + }); + + PigeonTypeNameFormat tnf; + + Uint8List type; + + Uint8List id; + + Uint8List payload; + + Object encode() { + return [ + tnf.index, + type, + id, + payload, + ]; + } + + static PigeonNdefRecord decode(Object result) { + result as List; + return PigeonNdefRecord( + tnf: PigeonTypeNameFormat.values[result[0]! as int], + type: result[1]! as Uint8List, + id: result[2]! as Uint8List, + payload: result[3]! as Uint8List, + ); + } +} + +class _PigeonFlutterApiCodec extends StandardMessageCodec { + const _PigeonFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonIsoDep) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is PigeonMifareClassic) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is PigeonMifareUltralight) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdef) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefMessage) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefRecord) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcA) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcB) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcBarcode) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcF) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcV) { + buffer.putUint8(138); + writeValue(buffer, value.encode()); + } else if (value is PigeonTag) { + buffer.putUint8(139); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return PigeonIsoDep.decode(readValue(buffer)!); + case 129: + return PigeonMifareClassic.decode(readValue(buffer)!); + case 130: + return PigeonMifareUltralight.decode(readValue(buffer)!); + case 131: + return PigeonNdef.decode(readValue(buffer)!); + case 132: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 133: + return PigeonNdefRecord.decode(readValue(buffer)!); + case 134: + return PigeonNfcA.decode(readValue(buffer)!); + case 135: + return PigeonNfcB.decode(readValue(buffer)!); + case 136: + return PigeonNfcBarcode.decode(readValue(buffer)!); + case 137: + return PigeonNfcF.decode(readValue(buffer)!); + case 138: + return PigeonNfcV.decode(readValue(buffer)!); + case 139: + return PigeonTag.decode(readValue(buffer)!); + default: + return super.readValueOfType(type, buffer); + } + } +} + +abstract class PigeonFlutterApi { + static const MessageCodec pigeonChannelCodec = + _PigeonFlutterApiCodec(); + + void onTagDiscovered(PigeonTag tag); + + void onAdapterStateChanged(int state); + + static void setup(PigeonFlutterApi? api, {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onTagDiscovered', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onTagDiscovered was null.'); + final List args = (message as List?)!; + final PigeonTag? arg_tag = (args[0] as PigeonTag?); + assert(arg_tag != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onTagDiscovered was null, expected non-null PigeonTag.'); + try { + api.onTagDiscovered(arg_tag!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onAdapterStateChanged', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onAdapterStateChanged was null.'); + final List args = (message as List?)!; + final int? arg_state = (args[0] as int?); + assert(arg_state != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.onAdapterStateChanged was null, expected non-null int.'); + try { + api.onAdapterStateChanged(arg_state!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } +} + +class _PigeonHostApiCodec extends StandardMessageCodec { + const _PigeonHostApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonNdefMessage) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefMessage) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefRecord) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 129: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 130: + return PigeonNdefRecord.decode(readValue(buffer)!); + default: + return super.readValueOfType(type, buffer); + } + } +} + +class PigeonHostApi { + /// Constructor for [PigeonHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + PigeonHostApi({BinaryMessenger? binaryMessenger}) + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonHostApiCodec(); + + Future nfcAdapterIsEnabled() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsEnabled'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future nfcAdapterIsSecureNfcEnabled() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsSecureNfcEnabled'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future nfcAdapterIsSecureNfcSupported() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterIsSecureNfcSupported'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future nfcAdapterEnableReaderMode( + {required List flags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterEnableReaderMode'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([flags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future nfcAdapterDisableReaderMode() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterDisableReaderMode'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future nfcAdapterEnableForegroundDispatch() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterEnableForegroundDispatch'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future nfcAdapterDisableForegroundDispatch() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAdapterDisableForegroundDispatch'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future ndefGetNdefMessage( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefGetNdefMessage'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as PigeonNdefMessage?); + } + } + + Future ndefWriteNdefMessage( + {required String handle, required PigeonNdefMessage message}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteNdefMessage'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, message]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future ndefMakeReadOnly({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefMakeReadOnly'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future nfcAGetMaxTransceiveLength({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcAGetTimeout({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcAGetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcASetTimeout( + {required String handle, required int timeout}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcASetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, timeout]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future nfcATransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcATransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future nfcBGetMaxTransceiveLength({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcBGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcBTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcBTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future nfcFGetMaxTransceiveLength({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcFGetTimeout({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFGetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcFSetTimeout( + {required String handle, required int timeout}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFSetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, timeout]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future nfcFTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcFTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future nfcVGetMaxTransceiveLength({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcVGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future nfcVTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.nfcVTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future isoDepGetMaxTransceiveLength({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future isoDepGetTimeout({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepGetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future isoDepSetTimeout( + {required String handle, required int timeout}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepSetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, timeout]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future isoDepTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.isoDepTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future mifareClassicGetMaxTransceiveLength( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareClassicGetTimeout({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareClassicSetTimeout( + {required String handle, required int timeout}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicSetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, timeout]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicBlockToSector( + {required String handle, required int blockIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicBlockToSector'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareClassicGetBlockCountInSector( + {required String handle, required int sectorIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicGetBlockCountInSector'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, sectorIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareClassicSectorToBlock( + {required String handle, required int sectorIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicSectorToBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, sectorIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareClassicAuthenticateSectorWithKeyA({ + required String handle, + required int sectorIndex, + required Uint8List key, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicAuthenticateSectorWithKeyA'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, sectorIndex, key]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future mifareClassicAuthenticateSectorWithKeyB({ + required String handle, + required int sectorIndex, + required Uint8List key, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicAuthenticateSectorWithKeyB'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, sectorIndex, key]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future mifareClassicIncrement({ + required String handle, + required int blockIndex, + required int value, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicIncrement'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex, value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicDecrement({ + required String handle, + required int blockIndex, + required int value, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicDecrement'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex, value]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicReadBlock( + {required String handle, required int blockIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicReadBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future mifareClassicWriteBlock({ + required String handle, + required int blockIndex, + required Uint8List data, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicWriteBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex, data]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicRestore( + {required String handle, required int blockIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicRestore'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicTransfer( + {required String handle, required int blockIndex}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicTransfer'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, blockIndex]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareClassicTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareClassicTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future mifareUltralightGetMaxTransceiveLength( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightGetMaxTransceiveLength'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareUltralightGetTimeout({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightGetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future mifareUltralightSetTimeout( + {required String handle, required int timeout}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightSetTimeout'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, timeout]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareUltralightReadPages( + {required String handle, required int pageOffset}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightReadPages'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, pageOffset]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future mifareUltralightWritePage({ + required String handle, + required int pageOffset, + required Uint8List data, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightWritePage'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, pageOffset, data]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future mifareUltralightTransceive( + {required String handle, required Uint8List bytes}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.mifareUltralightTransceive'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, bytes]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future ndefFormatableFormat( + {required String handle, required PigeonNdefMessage firstMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefFormatableFormat'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, firstMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future ndefFormatableFormatReadOnly( + {required String handle, required PigeonNdefMessage firstMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefFormatableFormatReadOnly'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, firstMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } +} diff --git a/lib/src/nfc_manager_android/tags/iso_dep.dart b/lib/src/nfc_manager_android/tags/iso_dep.dart new file mode 100644 index 0000000..ab37dff --- /dev/null +++ b/lib/src/nfc_manager_android/tags/iso_dep.dart @@ -0,0 +1,81 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to ISO-DEP (ISO 14443-4) operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class IsoDepAndroid { + const IsoDepAndroid._( + this._handle, { + required this.tag, + required this.hiLayerResponse, + required this.historicalBytes, + required this.isExtendedLengthApduSupported, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final Uint8List? hiLayerResponse; + + /// DOC: + final Uint8List? historicalBytes; + + /// DOC: + final bool isExtendedLengthApduSupported; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static IsoDepAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.isoDep; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return IsoDepAndroid._( + data.handle, + tag: _tag, + hiLayerResponse: tech.hiLayerResponse, + historicalBytes: tech.historicalBytes, + isExtendedLengthApduSupported: tech.isExtendedLengthApduSupported, + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.isoDepGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future getTimeout() { + return hostApi.isoDepGetTimeout( + handle: _handle, + ); + } + + /// DOC: + Future setTimeout(int timeout) { + return hostApi.isoDepSetTimeout( + handle: _handle, + timeout: timeout, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.isoDepTransceive( + handle: _handle, + bytes: bytes, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/mifare_classic.dart b/lib/src/nfc_manager_android/tags/mifare_classic.dart new file mode 100644 index 0000000..aef4426 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/mifare_classic.dart @@ -0,0 +1,169 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to MIFARE Classic operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class MifareClassicAndroid { + const MifareClassicAndroid._( + this._handle, { + required this.tag, + required this.type, + required this.blockCount, + required this.sectorCount, + required this.size, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final MifareClassicTypeAndroid type; + + /// DOC: + final int blockCount; + + /// DOC: + final int sectorCount; + + /// DOC: + final int size; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static MifareClassicAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.mifareClassic; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return MifareClassicAndroid._( + data.handle, + tag: _tag, + type: MifareClassicTypeAndroid.values.byName(tech.type.name), + blockCount: tech.blockCount, + sectorCount: tech.sectorCount, + size: tech.size, + ); + } + + /// DOC: + Future authenticateSectorWithKeyA({ + required int sectorIndex, + required Uint8List key, + }) { + return hostApi.mifareClassicAuthenticateSectorWithKeyA( + handle: _handle, + sectorIndex: sectorIndex, + key: key, + ); + } + + /// DOC: + Future authenticateSectorWithKeyB({ + required int sectorIndex, + required Uint8List key, + }) { + return hostApi.mifareClassicAuthenticateSectorWithKeyB( + handle: _handle, + sectorIndex: sectorIndex, + key: key, + ); + } + + /// DOC: + Future increment({ + required int blockIndex, + required int value, + }) { + return hostApi.mifareClassicIncrement( + handle: _handle, + blockIndex: blockIndex, + value: value, + ); + } + + /// DOC: + Future decrement({ + required int blockIndex, + required int value, + }) { + return hostApi.mifareClassicDecrement( + handle: _handle, + blockIndex: blockIndex, + value: value, + ); + } + + /// DOC: + Future readBlock({ + required int blockIndex, + }) { + return hostApi.mifareClassicReadBlock( + handle: _handle, + blockIndex: blockIndex, + ); + } + + /// DOC: + Future writeBlock({ + required int blockIndex, + required Uint8List data, + }) { + return hostApi.mifareClassicWriteBlock( + handle: _handle, + blockIndex: blockIndex, + data: data, + ); + } + + /// DOC: + Future restore({ + required int blockIndex, + }) { + return hostApi.mifareClassicRestore( + handle: _handle, + blockIndex: blockIndex, + ); + } + + /// DOC: + Future transfer({ + required int blockIndex, + }) { + return hostApi.mifareClassicTransfer( + handle: _handle, + blockIndex: blockIndex, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.mifareClassicTransceive( + handle: _handle, + bytes: bytes, + ); + } +} + +/// DOC: +enum MifareClassicTypeAndroid { + /// DOC: + classic, + + /// DOC: + plus, + + /// DOC: + pro, + + /// DOC: + unknown, +} diff --git a/lib/src/nfc_manager_android/tags/mifare_ultralight.dart b/lib/src/nfc_manager_android/tags/mifare_ultralight.dart new file mode 100644 index 0000000..0b98686 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/mifare_ultralight.dart @@ -0,0 +1,105 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to MIFARE Ultralight operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class MifareUltralightAndroid { + const MifareUltralightAndroid._( + this._handle, { + required this.tag, + required this.type, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final MifareUltralightTypeAndroid type; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static MifareUltralightAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.mifareUltralight; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return MifareUltralightAndroid._( + data.handle, + tag: _tag, + type: MifareUltralightTypeAndroid.values.byName(tech.type.name), + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.mifareUltralightGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future getTimeout() { + return hostApi.mifareUltralightGetTimeout( + handle: _handle, + ); + } + + /// DOC: + Future setTimeout(int timeout) { + return hostApi.mifareUltralightSetTimeout( + handle: _handle, + timeout: timeout, + ); + } + + /// DOC: + Future readPages({ + required int pageOffset, + }) { + return hostApi.mifareUltralightReadPages( + handle: _handle, + pageOffset: pageOffset, + ); + } + + /// DOC: + Future writePage({ + required int pageOffset, + required Uint8List data, + }) { + return hostApi.mifareUltralightWritePage( + handle: _handle, + pageOffset: pageOffset, + data: data, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.mifareUltralightTransceive( + handle: _handle, + bytes: bytes, + ); + } +} + +/// DOC: +enum MifareUltralightTypeAndroid { + /// DOC: + ultralight, + + /// DOC: + ultralightC, + + /// DOC: + unknown, +} diff --git a/lib/src/nfc_manager_android/tags/ndef.dart b/lib/src/nfc_manager_android/tags/ndef.dart new file mode 100644 index 0000000..7d9e78d --- /dev/null +++ b/lib/src/nfc_manager_android/tags/ndef.dart @@ -0,0 +1,120 @@ +import 'package:ndef_record/ndef_record.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NDEF operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NdefAndroid { + const NdefAndroid._( + this._handle, { + required this.tag, + required this.type, + required this.maxSize, + required this.canMakeReadOnly, + required this.isWritable, + required this.cachedNdefMessage, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final String type; + + /// DOC: + final int maxSize; + + /// DOC: + final bool canMakeReadOnly; + + /// DOC: + final bool isWritable; + + /// DOC: + final NdefMessage? cachedNdefMessage; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NdefAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.ndef; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NdefAndroid._( + data.handle, + tag: _tag, + type: tech.type, + maxSize: tech.maxSize, + canMakeReadOnly: tech.canMakeReadOnly, + isWritable: tech.isWritable, + cachedNdefMessage: tech.cachedNdefMessage == null + ? null + : NdefMessage( + records: tech.cachedNdefMessage!.records + .map((r) => NdefRecord( + typeNameFormat: TypeNameFormat.values.byName( + r!.tnf.name, + ), + type: r.type, + identifier: r.id, + payload: r.payload, + )) + .toList(), + ), + ); + } + + /// DOC: + Future getNdefMessage() { + return hostApi + .ndefGetNdefMessage( + handle: _handle, + ) + .then((value) => value == null + ? null + : NdefMessage( + records: value.records + .map((r) => NdefRecord( + typeNameFormat: TypeNameFormat.values.byName( + r!.tnf.name, + ), + type: r.type, + identifier: r.id, + payload: r.payload, + )) + .toList(), + )); + } + + /// DOC: + Future writeNdefMessage(NdefMessage message) { + return hostApi.ndefWriteNdefMessage( + handle: _handle, + message: PigeonNdefMessage( + records: message.records + .map((e) => PigeonNdefRecord( + tnf: PigeonTypeNameFormat.values.byName( + e.typeNameFormat.name, + ), + type: e.type, + id: e.identifier, + payload: e.payload, + )) + .toList(), + )); + } + + /// DOC: + Future makeReadOnly() { + return hostApi.ndefMakeReadOnly( + handle: _handle, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/ndef_formatable.dart b/lib/src/nfc_manager_android/tags/ndef_formatable.dart new file mode 100644 index 0000000..1236fe6 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/ndef_formatable.dart @@ -0,0 +1,65 @@ +import 'package:ndef_record/ndef_record.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NDEF format operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NdefFormatableAndroid { + const NdefFormatableAndroid._(this._handle, {required this.tag}); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NdefFormatableAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.ndefFormatable; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NdefFormatableAndroid._(data.handle, tag: _tag); + } + + /// DOC: + Future format(NdefMessage firstMessage) { + return hostApi.ndefFormatableFormat( + handle: _handle, + firstMessage: PigeonNdefMessage( + records: firstMessage.records + .map((e) => PigeonNdefRecord( + tnf: PigeonTypeNameFormat.values.byName( + e.typeNameFormat.name, + ), + type: e.type, + id: e.identifier, + payload: e.payload, + )) + .toList(), + )); + } + + /// DOC: + Future formatReadOnly(NdefMessage firstMessage) { + return hostApi.ndefFormatableFormatReadOnly( + handle: _handle, + firstMessage: PigeonNdefMessage( + records: firstMessage.records + .map((e) => PigeonNdefRecord( + tnf: PigeonTypeNameFormat.values.byName( + e.typeNameFormat.name, + ), + type: e.type, + id: e.identifier, + payload: e.payload, + )) + .toList(), + )); + } +} diff --git a/lib/src/nfc_manager_android/tags/nfc_a.dart b/lib/src/nfc_manager_android/tags/nfc_a.dart new file mode 100644 index 0000000..bef65cc --- /dev/null +++ b/lib/src/nfc_manager_android/tags/nfc_a.dart @@ -0,0 +1,76 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NFC-A (ISO 14443-3A) operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NfcAAndroid { + const NfcAAndroid._( + this._handle, { + required this.tag, + required this.atqa, + required this.sak, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final Uint8List atqa; + + /// DOC: + final int sak; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcAAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.nfcA; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NfcAAndroid._( + data.handle, + tag: _tag, + atqa: tech.atqa, + sak: tech.sak, + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.nfcAGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future getTimeout() { + return hostApi.nfcAGetTimeout( + handle: _handle, + ); + } + + /// DOC: + Future setTimeout(int timeout) { + return hostApi.nfcASetTimeout( + handle: _handle, + timeout: timeout, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.nfcATransceive( + handle: _handle, + bytes: bytes, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/nfc_b.dart b/lib/src/nfc_manager_android/tags/nfc_b.dart new file mode 100644 index 0000000..6622844 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/nfc_b.dart @@ -0,0 +1,61 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NFC-B (ISO 14443-3B) operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NfcBAndroid { + const NfcBAndroid._( + this._handle, { + required this.tag, + required this.applicationData, + required this.protocolInfo, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final Uint8List applicationData; + + /// DOC: + final Uint8List protocolInfo; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcBAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.nfcB; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NfcBAndroid._( + data.handle, + tag: _tag, + applicationData: tech.applicationData, + protocolInfo: tech.protocolInfo, + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.nfcBGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.nfcBTransceive( + handle: _handle, + bytes: bytes, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/nfc_barcode.dart b/lib/src/nfc_manager_android/tags/nfc_barcode.dart new file mode 100644 index 0000000..9358515 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/nfc_barcode.dart @@ -0,0 +1,46 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to tags containing just a barcode for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NfcBarcodeAndroid { + const NfcBarcodeAndroid._( + this._handle, { + required this.tag, + required this.type, + required this.barcode, + }); + + // ignore: unused_field + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final int type; + + /// DOC: + final Uint8List barcode; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcBarcodeAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.nfcBarcode; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NfcBarcodeAndroid._( + data.handle, + tag: _tag, + type: tech.type, + barcode: tech.barcode, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/nfc_f.dart b/lib/src/nfc_manager_android/tags/nfc_f.dart new file mode 100644 index 0000000..d8cabde --- /dev/null +++ b/lib/src/nfc_manager_android/tags/nfc_f.dart @@ -0,0 +1,76 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NFC-F (JIS 6319-4) operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NfcFAndroid { + const NfcFAndroid._( + this._handle, { + required this.tag, + required this.manufacturer, + required this.systemCode, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final Uint8List manufacturer; + + /// DOC: + final Uint8List systemCode; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcFAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.nfcF; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NfcFAndroid._( + data.handle, + tag: _tag, + manufacturer: tech.manufacturer, + systemCode: tech.systemCode, + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.nfcFGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future getTimeout() { + return hostApi.nfcFGetTimeout( + handle: _handle, + ); + } + + /// DOC: + Future setTimeout(int timeout) { + return hostApi.nfcFSetTimeout( + handle: _handle, + timeout: timeout, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.nfcFTransceive( + handle: _handle, + bytes: bytes, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/nfc_v.dart b/lib/src/nfc_manager_android/tags/nfc_v.dart new file mode 100644 index 0000000..c722a79 --- /dev/null +++ b/lib/src/nfc_manager_android/tags/nfc_v.dart @@ -0,0 +1,61 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_android/tags/tag.dart'; + +/// The class providing access to NFC-V (ISO 15693) operations for Android. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NfcVAndroid { + const NfcVAndroid._( + this._handle, { + required this.tag, + required this.dsfId, + required this.responseFlags, + }); + + final String _handle; + + /// DOC: + final NfcTagAndroid tag; + + /// DOC: + final int dsfId; + + /// DOC: + final int responseFlags; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcVAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.nfcV; + final _tag = NfcTagAndroid.from(tag); + if (data == null || tech == null || _tag == null) return null; + return NfcVAndroid._( + data.handle, + tag: _tag, + dsfId: tech.dsfId, + responseFlags: tech.responseFlags, + ); + } + + /// DOC: + Future getMaxTransceiveLength() { + return hostApi.nfcVGetMaxTransceiveLength( + handle: _handle, + ); + } + + /// DOC: + Future transceive(Uint8List bytes) { + return hostApi.nfcVTransceive( + handle: _handle, + bytes: bytes, + ); + } +} diff --git a/lib/src/nfc_manager_android/tags/tag.dart b/lib/src/nfc_manager_android/tags/tag.dart new file mode 100644 index 0000000..60f43ca --- /dev/null +++ b/lib/src/nfc_manager_android/tags/tag.dart @@ -0,0 +1,31 @@ +import 'dart:typed_data'; + +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_android/pigeon.g.dart'; + +/// DOC: +final class NfcTagAndroid { + const NfcTagAndroid._({ + required this.id, + required this.techList, + }); + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NfcTagAndroid? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + if (data == null) return null; + return NfcTagAndroid._( + id: data.id, + techList: data.techList.cast(), + ); + } + + /// DOC: + final Uint8List id; + + /// DOC: + final List techList; +} diff --git a/lib/src/nfc_manager_ios/nfc_manager.dart b/lib/src/nfc_manager_ios/nfc_manager.dart new file mode 100644 index 0000000..8f04512 --- /dev/null +++ b/lib/src/nfc_manager_ios/nfc_manager.dart @@ -0,0 +1,342 @@ +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +// The entry point for accessing the NFC session on iOS. +final class NfcManagerIOS { + NfcManagerIOS._() { + _NfcManagerIOSFlutterApi(this); + } + + /// The instance of the [NfcManagerIOS] to use. + static NfcManagerIOS get instance => _instance ??= NfcManagerIOS._(); + static NfcManagerIOS? _instance; + + void Function(NfcTag)? _tagReaderSessionDidDetectTag; + void Function()? _tagReaderSessionDidBecomeActive; + void Function(NfcReaderSessionErrorIOS)? + _tagReaderSessionDidInvalidateWithError; + void Function(List)? _vasReaderSessionDidReceive; + void Function()? _vasReaderSessionDidBecomeActive; + void Function(NfcReaderSessionErrorIOS)? + _vasReaderSessionDidInvalidateWithError; + + /// DOC: + Future tagReaderSessionReadingAvailable() { + return hostApi.tagReaderSessionReadingAvailable(); + } + + /// DOC: + Future tagReaderSessionBegin({ + required Set pollingOptions, + required void Function(NfcTag)? didDetectTag, + void Function()? didBecomeActive, + void Function(NfcReaderSessionErrorIOS)? didInvalidateWithError, + String? alertMessage, + bool invalidateAfterFirstRead = true, + }) { + _tagReaderSessionDidDetectTag = didDetectTag; + _tagReaderSessionDidBecomeActive = didBecomeActive; + _tagReaderSessionDidInvalidateWithError = didInvalidateWithError; + return hostApi.tagReaderSessionBegin( + pollingOptions: pollingOptions.map((e) => e.name).toList(), + alertMessage: alertMessage, + invalidateAfterFirstRead: invalidateAfterFirstRead, + ); + } + + /// DOC: + Future tagReaderSessionInvalidate({ + String? alertMessage, + String? errorMessage, + }) { + _tagReaderSessionDidDetectTag = null; + _tagReaderSessionDidBecomeActive = null; + _tagReaderSessionDidInvalidateWithError = null; + return hostApi.tagReaderSessionInvalidate( + alertMessage: alertMessage, + errorMessage: errorMessage, + ); + } + + /// DOC: + Future tagReaderSessionSetAlertMessage({required String alertMessage}) { + return hostApi.tagReaderSessionSetAlertMessage( + alertMessage: alertMessage, + ); + } + + /// DOC: + Future tagReaderSessionRestartPolling() { + return hostApi.tagReaderSessionRestartPolling(); + } + + /// DOC: + Future vasReaderSessionBegin({ + required List configurations, + required void Function(List configurations) didReceive, + void Function()? didBecomeActive, + void Function(NfcReaderSessionErrorIOS error)? didInvalidateWithError, + String? alertMessage, + }) { + _vasReaderSessionDidBecomeActive = didBecomeActive; + _vasReaderSessionDidInvalidateWithError = didInvalidateWithError; + _vasReaderSessionDidReceive = didReceive; + return hostApi.vasReaderSessionBegin( + configurations: configurations + .map((e) => PigeonNfcVasCommandConfiguration( + mode: PigeonNfcVasCommandConfigurationMode.values.byName( + e.mode.name, + ), + passIdentifier: e.passIdentifier, + url: e.url?.toString(), + )) + .toList(), + alertMessage: alertMessage, + ); + } + + /// DOC: + Future vasReaderSessionInvalidate({ + String? alertMessage, + String? errorMessage, + }) { + _vasReaderSessionDidBecomeActive = null; + _vasReaderSessionDidInvalidateWithError = null; + _vasReaderSessionDidReceive = null; + return hostApi.vasReaderSessionInvalidate( + alertMessage: alertMessage, + errorMessage: errorMessage, + ); + } + + /// DOC: + Future vasReaderSessionSetAlertMessage({required String alertMessage}) { + return hostApi.vasReaderSessionSetAlertMessage( + alertMessage: alertMessage, + ); + } +} + +class _NfcManagerIOSFlutterApi implements PigeonFlutterApi { + _NfcManagerIOSFlutterApi(this._instance) { + PigeonFlutterApi.setup(this); + } + + final NfcManagerIOS _instance; + + @override + void tagReaderSessionDidBecomeActive() { + _instance._tagReaderSessionDidBecomeActive?.call(); + } + + @override + void tagReaderSessionDidInvalidateWithError( + PigeonNfcReaderSessionError error, + ) { + _instance._tagReaderSessionDidInvalidateWithError?.call( + NfcReaderSessionErrorIOS( + code: NfcReaderErrorCodeIOS.values.byName(error.code.name), + message: error.message, + ), + ); + } + + @override + void tagReaderSessionDidDetect(PigeonTag tag) { + _instance._tagReaderSessionDidDetectTag?.call( + // ignore: invalid_use_of_visible_for_testing_member + NfcTag(data: tag), + ); + } + + @override + void vasReaderSessionDidBecomeActive() { + _instance._vasReaderSessionDidBecomeActive?.call(); + } + + @override + void vasReaderSessionDidInvalidateWithError( + PigeonNfcReaderSessionError error, + ) { + _instance._vasReaderSessionDidInvalidateWithError?.call( + NfcReaderSessionErrorIOS( + code: NfcReaderErrorCodeIOS.values.byName(error.code.name), + message: error.message, + ), + ); + } + + @override + void vasReaderSessionDidReceive(List responses) { + _instance._vasReaderSessionDidReceive?.call(responses + .map((e) => NfcVasResponseIOS( + status: NfcVasResponseErrorCodeIOS.values.byName(e!.status.name), + vasData: e.vasData, + mobileToken: e.mobileToken, + )) + .toList()); + } +} + +/// DOC: +final class NfcVasCommandConfigurationIOS { + /// DOC: + @visibleForTesting + const NfcVasCommandConfigurationIOS({ + required this.mode, + required this.passIdentifier, + this.url, + }); + + /// DOC: + final NfcVasCommandConfigurationModeIOS mode; + + /// DOC: + final String passIdentifier; + + /// DOC: + final Uri? url; +} + +/// DOC: +final class NfcVasResponseIOS { + /// DOC: + @visibleForTesting + const NfcVasResponseIOS({ + required this.status, + required this.vasData, + required this.mobileToken, + }); + + /// DOC: + final NfcVasResponseErrorCodeIOS status; + + /// DOC: + final Uint8List vasData; + + /// DOC: + final Uint8List mobileToken; +} + +/// DOC: +final class NfcReaderSessionErrorIOS { + /// DOC: + @visibleForTesting + const NfcReaderSessionErrorIOS({ + required this.code, + required this.message, + }); + + /// DOC: + final NfcReaderErrorCodeIOS code; + + /// DOC: + final String message; +} + +/// DOC: +enum NfcVasCommandConfigurationModeIOS { + /// DOC: + normal, + + /// DOC: + urlOnly, +} + +/// DOC: +enum NfcReaderErrorCodeIOS { + /// DOC: + readerSessionInvalidationErrorFirstNDEFTagRead, + + /// DOC: + readerSessionInvalidationErrorSessionTerminatedUnexpectedly, + + /// DOC: + readerSessionInvalidationErrorSessionTimeout, + + /// DOC: + readerSessionInvalidationErrorSystemIsBusy, + + /// DOC: + readerSessionInvalidationErrorUserCanceled, + + /// DOC: + ndefReaderSessionErrorTagNotWritable, + + /// DOC: + ndefReaderSessionErrorTagSizeTooSmall, + + /// DOC: + ndefReaderSessionErrorTagUpdateFailure, + + /// DOC: + ndefReaderSessionErrorZeroLengthMessage, + + /// DOC: + readerTransceiveErrorRetryExceeded, + + /// DOC: + readerTransceiveErrorTagConnectionLost, + + /// DOC: + readerTransceiveErrorTagNotConnected, + + /// DOC: + readerTransceiveErrorTagResponseError, + + /// DOC: + readerTransceiveErrorSessionInvalidated, + + /// DOC: + readerTransceiveErrorPacketTooLong, + + /// DOC: + tagCommandConfigurationErrorInvalidParameters, + + /// DOC: + readerErrorUnsupportedFeature, + + /// DOC: + readerErrorInvalidParameter, + + /// DOC: + readerErrorInvalidParameterLength, + + /// DOC: + readerErrorParameterOutOfBound, + + /// DOC: + readerErrorRadioDisabled, + + /// DOC: + readerErrorSecurityViolation, +} + +/// DOC: +enum NfcVasResponseErrorCodeIOS { + /// DOC: + success, + + /// DOC: + userIntervention, + + /// DOC: + dataNotActivated, + + /// DOC: + dataNotFound, + + /// DOC: + incorrectData, + + /// DOC: + unsupportedApplicationVersion, + + /// DOC: + wrongLCField, + + /// DOC: + wrongParameters, +} diff --git a/lib/src/nfc_manager_ios/nfc_manager_platform.dart b/lib/src/nfc_manager_ios/nfc_manager_platform.dart new file mode 100644 index 0000000..efe8bef --- /dev/null +++ b/lib/src/nfc_manager_ios/nfc_manager_platform.dart @@ -0,0 +1,33 @@ +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/nfc_manager.dart'; + +class NfcManagerIOSPlatform implements NfcManager { + @override + Future isAvailable() { + return NfcManagerIOS.instance.tagReaderSessionReadingAvailable(); + } + + @override + Future startSession({ + required Set pollingOptions, + required void Function(NfcTag) onDiscovered, + String? alertMessageIOS, + bool invalidateAfterFirstReadIOS = true, + void Function(NfcReaderSessionErrorIOS)? onSessionErrorIOS, + }) { + return NfcManagerIOS.instance.tagReaderSessionBegin( + pollingOptions: pollingOptions, + alertMessage: alertMessageIOS, + didDetectTag: onDiscovered, + didInvalidateWithError: onSessionErrorIOS, + ); + } + + @override + Future stopSession({String? alertMessageIOS, String? errorMessageIOS}) { + return NfcManagerIOS.instance.tagReaderSessionInvalidate( + alertMessage: alertMessageIOS, + errorMessage: errorMessageIOS, + ); + } +} diff --git a/lib/src/nfc_manager_ios/pigeon.dart b/lib/src/nfc_manager_ios/pigeon.dart new file mode 100644 index 0000000..f71bc90 --- /dev/null +++ b/lib/src/nfc_manager_ios/pigeon.dart @@ -0,0 +1,3 @@ +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +final hostApi = PigeonHostApi(); diff --git a/lib/src/nfc_manager_ios/pigeon.g.dart b/lib/src/nfc_manager_ios/pigeon.g.dart new file mode 100644 index 0000000..7e9b476 --- /dev/null +++ b/lib/src/nfc_manager_ios/pigeon.g.dart @@ -0,0 +1,2368 @@ +// Autogenerated from Pigeon (v15.0.2), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers + +import 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; + +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:flutter/services.dart'; + +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + +enum PigeonNdefStatus { + notSupported, + readWrite, + readOnly, +} + +enum PigeonTypeNameFormat { + empty, + wellKnown, + media, + absoluteUri, + external, + unknown, + unchanged, +} + +enum PigeonFeliCaPollingRequestCode { + noRequest, + systemCode, + communicationPerformance, +} + +enum PigeonFeliCaPollingTimeSlot { + max1, + max2, + max4, + max8, + max16, +} + +enum PigeonMiFareFamily { + unknown, + ultralight, + plus, + desfire, +} + +enum PigeonNfcVasCommandConfigurationMode { + normal, + urlOnly, +} + +enum PigeonNfcReaderErrorCode { + readerSessionInvalidationErrorFirstNDEFTagRead, + readerSessionInvalidationErrorSessionTerminatedUnexpectedly, + readerSessionInvalidationErrorSessionTimeout, + readerSessionInvalidationErrorSystemIsBusy, + readerSessionInvalidationErrorUserCanceled, + ndefReaderSessionErrorTagNotWritable, + ndefReaderSessionErrorTagSizeTooSmall, + ndefReaderSessionErrorTagUpdateFailure, + ndefReaderSessionErrorZeroLengthMessage, + readerTransceiveErrorRetryExceeded, + readerTransceiveErrorTagConnectionLost, + readerTransceiveErrorTagNotConnected, + readerTransceiveErrorTagResponseError, + readerTransceiveErrorSessionInvalidated, + readerTransceiveErrorPacketTooLong, + tagCommandConfigurationErrorInvalidParameters, + readerErrorUnsupportedFeature, + readerErrorInvalidParameter, + readerErrorInvalidParameterLength, + readerErrorParameterOutOfBound, + readerErrorRadioDisabled, + readerErrorSecurityViolation, +} + +enum PigeonNfcVasResponseErrorCode { + success, + userIntervention, + dataNotActivated, + dataNotFound, + incorrectData, + unsupportedApplicationVersion, + wrongLCField, + wrongParameters, +} + +class PigeonTag { + PigeonTag({ + required this.handle, + this.ndef, + this.feliCa, + this.iso15693, + this.iso7816, + this.miFare, + }); + + String handle; + + PigeonNdef? ndef; + + PigeonFeliCa? feliCa; + + PigeonISO15693? iso15693; + + PigeonISO7816? iso7816; + + PigeonMiFare? miFare; + + Object encode() { + return [ + handle, + ndef?.encode(), + feliCa?.encode(), + iso15693?.encode(), + iso7816?.encode(), + miFare?.encode(), + ]; + } + + static PigeonTag decode(Object result) { + result as List; + return PigeonTag( + handle: result[0]! as String, + ndef: result[1] != null + ? PigeonNdef.decode(result[1]! as List) + : null, + feliCa: result[2] != null + ? PigeonFeliCa.decode(result[2]! as List) + : null, + iso15693: result[3] != null + ? PigeonISO15693.decode(result[3]! as List) + : null, + iso7816: result[4] != null + ? PigeonISO7816.decode(result[4]! as List) + : null, + miFare: result[5] != null + ? PigeonMiFare.decode(result[5]! as List) + : null, + ); + } +} + +class PigeonNdef { + PigeonNdef({ + required this.status, + required this.capacity, + this.cachedNdefMessage, + }); + + PigeonNdefStatus status; + + int capacity; + + PigeonNdefMessage? cachedNdefMessage; + + Object encode() { + return [ + status.index, + capacity, + cachedNdefMessage?.encode(), + ]; + } + + static PigeonNdef decode(Object result) { + result as List; + return PigeonNdef( + status: PigeonNdefStatus.values[result[0]! as int], + capacity: result[1]! as int, + cachedNdefMessage: result[2] != null + ? PigeonNdefMessage.decode(result[2]! as List) + : null, + ); + } +} + +class PigeonFeliCa { + PigeonFeliCa({ + required this.currentSystemCode, + required this.currentIDm, + }); + + Uint8List currentSystemCode; + + Uint8List currentIDm; + + Object encode() { + return [ + currentSystemCode, + currentIDm, + ]; + } + + static PigeonFeliCa decode(Object result) { + result as List; + return PigeonFeliCa( + currentSystemCode: result[0]! as Uint8List, + currentIDm: result[1]! as Uint8List, + ); + } +} + +class PigeonISO15693 { + PigeonISO15693({ + required this.icManufacturerCode, + required this.icSerialNumber, + required this.identifier, + }); + + int icManufacturerCode; + + Uint8List icSerialNumber; + + Uint8List identifier; + + Object encode() { + return [ + icManufacturerCode, + icSerialNumber, + identifier, + ]; + } + + static PigeonISO15693 decode(Object result) { + result as List; + return PigeonISO15693( + icManufacturerCode: result[0]! as int, + icSerialNumber: result[1]! as Uint8List, + identifier: result[2]! as Uint8List, + ); + } +} + +class PigeonISO7816 { + PigeonISO7816({ + required this.initialSelectedAID, + required this.identifier, + this.historicalBytes, + this.applicationData, + required this.proprietaryApplicationDataCoding, + }); + + String initialSelectedAID; + + Uint8List identifier; + + Uint8List? historicalBytes; + + Uint8List? applicationData; + + bool proprietaryApplicationDataCoding; + + Object encode() { + return [ + initialSelectedAID, + identifier, + historicalBytes, + applicationData, + proprietaryApplicationDataCoding, + ]; + } + + static PigeonISO7816 decode(Object result) { + result as List; + return PigeonISO7816( + initialSelectedAID: result[0]! as String, + identifier: result[1]! as Uint8List, + historicalBytes: result[2] as Uint8List?, + applicationData: result[3] as Uint8List?, + proprietaryApplicationDataCoding: result[4]! as bool, + ); + } +} + +class PigeonMiFare { + PigeonMiFare({ + required this.mifareFamily, + required this.identifier, + this.historicalBytes, + }); + + PigeonMiFareFamily mifareFamily; + + Uint8List identifier; + + Uint8List? historicalBytes; + + Object encode() { + return [ + mifareFamily.index, + identifier, + historicalBytes, + ]; + } + + static PigeonMiFare decode(Object result) { + result as List; + return PigeonMiFare( + mifareFamily: PigeonMiFareFamily.values[result[0]! as int], + identifier: result[1]! as Uint8List, + historicalBytes: result[2] as Uint8List?, + ); + } +} + +class PigeonNDEFQueryStatus { + PigeonNDEFQueryStatus({ + required this.status, + required this.capacity, + }); + + PigeonNdefStatus status; + + int capacity; + + Object encode() { + return [ + status.index, + capacity, + ]; + } + + static PigeonNDEFQueryStatus decode(Object result) { + result as List; + return PigeonNDEFQueryStatus( + status: PigeonNdefStatus.values[result[0]! as int], + capacity: result[1]! as int, + ); + } +} + +class PigeonNdefMessage { + PigeonNdefMessage({ + required this.records, + }); + + List records; + + Object encode() { + return [ + records, + ]; + } + + static PigeonNdefMessage decode(Object result) { + result as List; + return PigeonNdefMessage( + records: (result[0] as List?)!.cast(), + ); + } +} + +class PigeonNdefPayload { + PigeonNdefPayload({ + required this.typeNameFormat, + required this.type, + required this.identifier, + required this.payload, + }); + + PigeonTypeNameFormat typeNameFormat; + + Uint8List type; + + Uint8List identifier; + + Uint8List payload; + + Object encode() { + return [ + typeNameFormat.index, + type, + identifier, + payload, + ]; + } + + static PigeonNdefPayload decode(Object result) { + result as List; + return PigeonNdefPayload( + typeNameFormat: PigeonTypeNameFormat.values[result[0]! as int], + type: result[1]! as Uint8List, + identifier: result[2]! as Uint8List, + payload: result[3]! as Uint8List, + ); + } +} + +class PigeonFeliCaPollingResponse { + PigeonFeliCaPollingResponse({ + required this.manufacturerParameter, + required this.requestData, + }); + + Uint8List manufacturerParameter; + + Uint8List requestData; + + Object encode() { + return [ + manufacturerParameter, + requestData, + ]; + } + + static PigeonFeliCaPollingResponse decode(Object result) { + result as List; + return PigeonFeliCaPollingResponse( + manufacturerParameter: result[0]! as Uint8List, + requestData: result[1]! as Uint8List, + ); + } +} + +class PigeonFeliCaReadWithoutEncryptionResponse { + PigeonFeliCaReadWithoutEncryptionResponse({ + required this.statusFlag1, + required this.statusFlag2, + required this.blockData, + }); + + int statusFlag1; + + int statusFlag2; + + List blockData; + + Object encode() { + return [ + statusFlag1, + statusFlag2, + blockData, + ]; + } + + static PigeonFeliCaReadWithoutEncryptionResponse decode(Object result) { + result as List; + return PigeonFeliCaReadWithoutEncryptionResponse( + statusFlag1: result[0]! as int, + statusFlag2: result[1]! as int, + blockData: (result[2] as List?)!.cast(), + ); + } +} + +class PigeonFeliCaRequestServiceV2Response { + PigeonFeliCaRequestServiceV2Response({ + required this.statusFlag1, + required this.statusFlag2, + required this.encryptionIdentifier, + required this.nodeKeyVersionListAES, + required this.nodeKeyVersionListDES, + }); + + int statusFlag1; + + int statusFlag2; + + int encryptionIdentifier; + + List nodeKeyVersionListAES; + + List nodeKeyVersionListDES; + + Object encode() { + return [ + statusFlag1, + statusFlag2, + encryptionIdentifier, + nodeKeyVersionListAES, + nodeKeyVersionListDES, + ]; + } + + static PigeonFeliCaRequestServiceV2Response decode(Object result) { + result as List; + return PigeonFeliCaRequestServiceV2Response( + statusFlag1: result[0]! as int, + statusFlag2: result[1]! as int, + encryptionIdentifier: result[2]! as int, + nodeKeyVersionListAES: (result[3] as List?)!.cast(), + nodeKeyVersionListDES: (result[4] as List?)!.cast(), + ); + } +} + +class PigeonFeliCaRequestSpecificationVersionResponse { + PigeonFeliCaRequestSpecificationVersionResponse({ + required this.statusFlag1, + required this.statusFlag2, + required this.basicVersion, + required this.optionVersion, + }); + + int statusFlag1; + + int statusFlag2; + + Uint8List basicVersion; + + Uint8List optionVersion; + + Object encode() { + return [ + statusFlag1, + statusFlag2, + basicVersion, + optionVersion, + ]; + } + + static PigeonFeliCaRequestSpecificationVersionResponse decode(Object result) { + result as List; + return PigeonFeliCaRequestSpecificationVersionResponse( + statusFlag1: result[0]! as int, + statusFlag2: result[1]! as int, + basicVersion: result[2]! as Uint8List, + optionVersion: result[3]! as Uint8List, + ); + } +} + +class PigeonFeliCaStatusFlag { + PigeonFeliCaStatusFlag({ + required this.statusFlag1, + required this.statusFlag2, + }); + + int statusFlag1; + + int statusFlag2; + + Object encode() { + return [ + statusFlag1, + statusFlag2, + ]; + } + + static PigeonFeliCaStatusFlag decode(Object result) { + result as List; + return PigeonFeliCaStatusFlag( + statusFlag1: result[0]! as int, + statusFlag2: result[1]! as int, + ); + } +} + +class PigeonISO7816APDU { + PigeonISO7816APDU({ + required this.instructionClass, + required this.instructionCode, + required this.p1Parameter, + required this.p2Parameter, + required this.data, + required this.expectedResponseLength, + }); + + int instructionClass; + + int instructionCode; + + int p1Parameter; + + int p2Parameter; + + Uint8List data; + + int expectedResponseLength; + + Object encode() { + return [ + instructionClass, + instructionCode, + p1Parameter, + p2Parameter, + data, + expectedResponseLength, + ]; + } + + static PigeonISO7816APDU decode(Object result) { + result as List; + return PigeonISO7816APDU( + instructionClass: result[0]! as int, + instructionCode: result[1]! as int, + p1Parameter: result[2]! as int, + p2Parameter: result[3]! as int, + data: result[4]! as Uint8List, + expectedResponseLength: result[5]! as int, + ); + } +} + +class PigeonISO7816ResponseAPDU { + PigeonISO7816ResponseAPDU({ + required this.payload, + required this.statusWord1, + required this.statusWord2, + }); + + Uint8List payload; + + int statusWord1; + + int statusWord2; + + Object encode() { + return [ + payload, + statusWord1, + statusWord2, + ]; + } + + static PigeonISO7816ResponseAPDU decode(Object result) { + result as List; + return PigeonISO7816ResponseAPDU( + payload: result[0]! as Uint8List, + statusWord1: result[1]! as int, + statusWord2: result[2]! as int, + ); + } +} + +class PigeonISO15693SystemInfo { + PigeonISO15693SystemInfo({ + required this.dataStorageFormatIdentifier, + required this.applicationFamilyIdentifier, + required this.blockSize, + required this.totalBlocks, + required this.icReference, + }); + + int dataStorageFormatIdentifier; + + int applicationFamilyIdentifier; + + int blockSize; + + int totalBlocks; + + int icReference; + + Object encode() { + return [ + dataStorageFormatIdentifier, + applicationFamilyIdentifier, + blockSize, + totalBlocks, + icReference, + ]; + } + + static PigeonISO15693SystemInfo decode(Object result) { + result as List; + return PigeonISO15693SystemInfo( + dataStorageFormatIdentifier: result[0]! as int, + applicationFamilyIdentifier: result[1]! as int, + blockSize: result[2]! as int, + totalBlocks: result[3]! as int, + icReference: result[4]! as int, + ); + } +} + +class PigeonNfcReaderSessionError { + PigeonNfcReaderSessionError({ + required this.code, + required this.message, + }); + + PigeonNfcReaderErrorCode code; + + String message; + + Object encode() { + return [ + code.index, + message, + ]; + } + + static PigeonNfcReaderSessionError decode(Object result) { + result as List; + return PigeonNfcReaderSessionError( + code: PigeonNfcReaderErrorCode.values[result[0]! as int], + message: result[1]! as String, + ); + } +} + +class PigeonNfcVasCommandConfiguration { + PigeonNfcVasCommandConfiguration({ + required this.mode, + required this.passIdentifier, + this.url, + }); + + PigeonNfcVasCommandConfigurationMode mode; + + String passIdentifier; + + String? url; + + Object encode() { + return [ + mode.index, + passIdentifier, + url, + ]; + } + + static PigeonNfcVasCommandConfiguration decode(Object result) { + result as List; + return PigeonNfcVasCommandConfiguration( + mode: PigeonNfcVasCommandConfigurationMode.values[result[0]! as int], + passIdentifier: result[1]! as String, + url: result[2] as String?, + ); + } +} + +class PigeonNfcVasResponse { + PigeonNfcVasResponse({ + required this.status, + required this.vasData, + required this.mobileToken, + }); + + PigeonNfcVasResponseErrorCode status; + + Uint8List vasData; + + Uint8List mobileToken; + + Object encode() { + return [ + status.index, + vasData, + mobileToken, + ]; + } + + static PigeonNfcVasResponse decode(Object result) { + result as List; + return PigeonNfcVasResponse( + status: PigeonNfcVasResponseErrorCode.values[result[0]! as int], + vasData: result[1]! as Uint8List, + mobileToken: result[2]! as Uint8List, + ); + } +} + +class _PigeonFlutterApiCodec extends StandardMessageCodec { + const _PigeonFlutterApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonFeliCa) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is PigeonISO15693) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is PigeonISO7816) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is PigeonMiFare) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdef) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefMessage) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefPayload) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcReaderSessionError) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcVasResponse) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is PigeonTag) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return PigeonFeliCa.decode(readValue(buffer)!); + case 129: + return PigeonISO15693.decode(readValue(buffer)!); + case 130: + return PigeonISO7816.decode(readValue(buffer)!); + case 131: + return PigeonMiFare.decode(readValue(buffer)!); + case 132: + return PigeonNdef.decode(readValue(buffer)!); + case 133: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 134: + return PigeonNdefPayload.decode(readValue(buffer)!); + case 135: + return PigeonNfcReaderSessionError.decode(readValue(buffer)!); + case 136: + return PigeonNfcVasResponse.decode(readValue(buffer)!); + case 137: + return PigeonTag.decode(readValue(buffer)!); + default: + return super.readValueOfType(type, buffer); + } + } +} + +abstract class PigeonFlutterApi { + static const MessageCodec pigeonChannelCodec = + _PigeonFlutterApiCodec(); + + void tagReaderSessionDidBecomeActive(); + + void tagReaderSessionDidDetect(PigeonTag tag); + + void tagReaderSessionDidInvalidateWithError( + PigeonNfcReaderSessionError error); + + void vasReaderSessionDidBecomeActive(); + + void vasReaderSessionDidReceive(List responses); + + void vasReaderSessionDidInvalidateWithError( + PigeonNfcReaderSessionError error); + + static void setup(PigeonFlutterApi? api, {BinaryMessenger? binaryMessenger}) { + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidBecomeActive', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + try { + api.tagReaderSessionDidBecomeActive(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidDetect', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidDetect was null.'); + final List args = (message as List?)!; + final PigeonTag? arg_tag = (args[0] as PigeonTag?); + assert(arg_tag != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidDetect was null, expected non-null PigeonTag.'); + try { + api.tagReaderSessionDidDetect(arg_tag!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidInvalidateWithError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidInvalidateWithError was null.'); + final List args = (message as List?)!; + final PigeonNfcReaderSessionError? arg_error = + (args[0] as PigeonNfcReaderSessionError?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.tagReaderSessionDidInvalidateWithError was null, expected non-null PigeonNfcReaderSessionError.'); + try { + api.tagReaderSessionDidInvalidateWithError(arg_error!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidBecomeActive', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + try { + api.vasReaderSessionDidBecomeActive(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidReceive', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidReceive was null.'); + final List args = (message as List?)!; + final List? arg_responses = + (args[0] as List?)?.cast(); + assert(arg_responses != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidReceive was null, expected non-null List.'); + try { + api.vasReaderSessionDidReceive(arg_responses!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + { + final BasicMessageChannel __pigeon_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidInvalidateWithError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + __pigeon_channel.setMessageHandler(null); + } else { + __pigeon_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidInvalidateWithError was null.'); + final List args = (message as List?)!; + final PigeonNfcReaderSessionError? arg_error = + (args[0] as PigeonNfcReaderSessionError?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.nfc_manager.PigeonFlutterApi.vasReaderSessionDidInvalidateWithError was null, expected non-null PigeonNfcReaderSessionError.'); + try { + api.vasReaderSessionDidInvalidateWithError(arg_error!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } +} + +class _PigeonHostApiCodec extends StandardMessageCodec { + const _PigeonHostApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonFeliCaPollingResponse) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else if (value is PigeonFeliCaReadWithoutEncryptionResponse) { + buffer.putUint8(129); + writeValue(buffer, value.encode()); + } else if (value is PigeonFeliCaRequestServiceV2Response) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is PigeonFeliCaRequestSpecificationVersionResponse) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is PigeonFeliCaStatusFlag) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is PigeonISO15693SystemInfo) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is PigeonISO7816APDU) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); + } else if (value is PigeonISO7816ResponseAPDU) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); + } else if (value is PigeonNDEFQueryStatus) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefMessage) { + buffer.putUint8(137); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefMessage) { + buffer.putUint8(138); + writeValue(buffer, value.encode()); + } else if (value is PigeonNdefPayload) { + buffer.putUint8(139); + writeValue(buffer, value.encode()); + } else if (value is PigeonNfcVasCommandConfiguration) { + buffer.putUint8(140); + writeValue(buffer, value.encode()); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return PigeonFeliCaPollingResponse.decode(readValue(buffer)!); + case 129: + return PigeonFeliCaReadWithoutEncryptionResponse.decode( + readValue(buffer)!); + case 130: + return PigeonFeliCaRequestServiceV2Response.decode(readValue(buffer)!); + case 131: + return PigeonFeliCaRequestSpecificationVersionResponse.decode( + readValue(buffer)!); + case 132: + return PigeonFeliCaStatusFlag.decode(readValue(buffer)!); + case 133: + return PigeonISO15693SystemInfo.decode(readValue(buffer)!); + case 134: + return PigeonISO7816APDU.decode(readValue(buffer)!); + case 135: + return PigeonISO7816ResponseAPDU.decode(readValue(buffer)!); + case 136: + return PigeonNDEFQueryStatus.decode(readValue(buffer)!); + case 137: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 138: + return PigeonNdefMessage.decode(readValue(buffer)!); + case 139: + return PigeonNdefPayload.decode(readValue(buffer)!); + case 140: + return PigeonNfcVasCommandConfiguration.decode(readValue(buffer)!); + default: + return super.readValueOfType(type, buffer); + } + } +} + +class PigeonHostApi { + /// Constructor for [PigeonHostApi]. The [binaryMessenger] named argument is + /// available for dependency injection. If it is left null, the default + /// BinaryMessenger will be used which routes to the host platform. + PigeonHostApi({BinaryMessenger? binaryMessenger}) + : __pigeon_binaryMessenger = binaryMessenger; + final BinaryMessenger? __pigeon_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonHostApiCodec(); + + Future tagReaderSessionReadingAvailable() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionReadingAvailable'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future tagReaderSessionBegin({ + required List pollingOptions, + required String? alertMessage, + required bool invalidateAfterFirstRead, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionBegin'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel.send( + [pollingOptions, alertMessage, invalidateAfterFirstRead]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future tagReaderSessionInvalidate( + {required String? alertMessage, required String? errorMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionInvalidate'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([alertMessage, errorMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future tagReaderSessionRestartPolling() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionRestartPolling'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future tagReaderSessionSetAlertMessage( + {required String alertMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.tagReaderSessionSetAlertMessage'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([alertMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future vasReaderSessionReadingAvailable() async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionReadingAvailable'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send(null) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as bool?)!; + } + } + + Future vasReaderSessionBegin( + {required List configurations, + required String? alertMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionBegin'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([configurations, alertMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future vasReaderSessionInvalidate( + {required String? alertMessage, required String? errorMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionInvalidate'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([alertMessage, errorMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future vasReaderSessionSetAlertMessage( + {required String alertMessage}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.vasReaderSessionSetAlertMessage'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([alertMessage]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future ndefQueryNDEFStatus( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefQueryNDEFStatus'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonNDEFQueryStatus?)!; + } + } + + Future ndefReadNDEF({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefReadNDEF'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return (__pigeon_replyList[0] as PigeonNdefMessage?); + } + } + + Future ndefWriteNDEF( + {required String handle, required PigeonNdefMessage message}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteNDEF'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, message]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future ndefWriteLock({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.ndefWriteLock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future feliCaPolling({ + required String handle, + required Uint8List systemCode, + required PigeonFeliCaPollingRequestCode requestCode, + required PigeonFeliCaPollingTimeSlot timeSlot, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaPolling'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel.send( + [handle, systemCode, requestCode.index, timeSlot.index]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonFeliCaPollingResponse?)!; + } + } + + Future> feliCaRequestService( + {required String handle, required List nodeCodeList}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestService'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, nodeCodeList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + Future feliCaRequestResponse({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestResponse'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as int?)!; + } + } + + Future + feliCaReadWithoutEncryption({ + required String handle, + required List serviceCodeList, + required List blockList, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaReadWithoutEncryption'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, serviceCodeList, blockList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] + as PigeonFeliCaReadWithoutEncryptionResponse?)!; + } + } + + Future feliCaWriteWithoutEncryption({ + required String handle, + required List serviceCodeList, + required List blockList, + required List blockData, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaWriteWithoutEncryption'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, serviceCodeList, blockList, blockData]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonFeliCaStatusFlag?)!; + } + } + + Future> feliCaRequestSystemCode( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestSystemCode'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + Future feliCaRequestServiceV2( + {required String handle, required List nodeCodeList}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestServiceV2'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, nodeCodeList]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonFeliCaRequestServiceV2Response?)!; + } + } + + Future + feliCaRequestSpecificationVersion({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaRequestSpecificationVersion'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] + as PigeonFeliCaRequestSpecificationVersionResponse?)!; + } + } + + Future feliCaResetMode( + {required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaResetMode'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonFeliCaStatusFlag?)!; + } + } + + Future feliCaSendFeliCaCommand( + {required String handle, required Uint8List commandPacket}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.feliCaSendFeliCaCommand'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, commandPacket]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future miFareSendMiFareCommand( + {required String handle, required Uint8List commandPacket}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareCommand'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, commandPacket]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future miFareSendMiFareISO7816Command( + {required String handle, required PigeonISO7816APDU apdu}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareISO7816Command'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, apdu]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonISO7816ResponseAPDU?)!; + } + } + + Future miFareSendMiFareISO7816CommandRaw( + {required String handle, required Uint8List data}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.miFareSendMiFareISO7816CommandRaw'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, data]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonISO7816ResponseAPDU?)!; + } + } + + Future iso7816SendCommand( + {required String handle, required PigeonISO7816APDU apdu}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso7816SendCommand'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, apdu]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonISO7816ResponseAPDU?)!; + } + } + + Future iso7816SendCommandRaw( + {required String handle, required Uint8List data}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso7816SendCommandRaw'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle, data]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonISO7816ResponseAPDU?)!; + } + } + + Future iso15693StayQuiet({required String handle}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693StayQuiet'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = + await __pigeon_channel.send([handle]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693ReadSingleBlock({ + required String handle, + required List requestFlags, + required int blockNumber, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ReadSingleBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, blockNumber]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } + + Future iso15693WriteSingleBlock({ + required String handle, + required List requestFlags, + required int blockNumber, + required Uint8List dataBlock, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteSingleBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, blockNumber, dataBlock]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693LockBlock({ + required String handle, + required List requestFlags, + required int blockNumber, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockBlock'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, blockNumber]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future> iso15693ReadMultipleBlocks({ + required String handle, + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ReadMultipleBlocks'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, blockNumber, numberOfBlocks]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + Future iso15693WriteMultipleBlocks({ + required String handle, + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + required List dataBlocks, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteMultipleBlocks'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([ + handle, + requestFlags, + blockNumber, + numberOfBlocks, + dataBlocks + ]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693Select( + {required String handle, required List requestFlags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693Select'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693ResetToReady( + {required String handle, required List requestFlags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693ResetToReady'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693WriteAfi({ + required String handle, + required List requestFlags, + required int afi, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteAfi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, afi]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693LockAfi( + {required String handle, required List requestFlags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockAfi'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693WriteDsfId({ + required String handle, + required List requestFlags, + required int dsfId, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693WriteDsfId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, dsfId]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693LockDsfId( + {required String handle, required List requestFlags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693LockDsfId'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else { + return; + } + } + + Future iso15693GetSystemInfo( + {required String handle, required List requestFlags}) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693GetSystemInfo'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as PigeonISO15693SystemInfo?)!; + } + } + + Future> iso15693GetMultipleBlockSecurityStatus({ + required String handle, + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693GetMultipleBlockSecurityStatus'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([handle, requestFlags, blockNumber, numberOfBlocks]) + as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as List?)!.cast(); + } + } + + Future iso15693CustomCommand({ + required String handle, + required List requestFlags, + required int customCommandCode, + required Uint8List customRequestParameters, + }) async { + const String __pigeon_channelName = + 'dev.flutter.pigeon.nfc_manager.PigeonHostApi.iso15693CustomCommand'; + final BasicMessageChannel __pigeon_channel = + BasicMessageChannel( + __pigeon_channelName, + pigeonChannelCodec, + binaryMessenger: __pigeon_binaryMessenger, + ); + final List? __pigeon_replyList = await __pigeon_channel + .send([ + handle, + requestFlags, + customCommandCode, + customRequestParameters + ]) as List?; + if (__pigeon_replyList == null) { + throw _createConnectionError(__pigeon_channelName); + } else if (__pigeon_replyList.length > 1) { + throw PlatformException( + code: __pigeon_replyList[0]! as String, + message: __pigeon_replyList[1] as String?, + details: __pigeon_replyList[2], + ); + } else if (__pigeon_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (__pigeon_replyList[0] as Uint8List?)!; + } + } +} diff --git a/lib/src/nfc_manager_ios/tags/felica.dart b/lib/src/nfc_manager_ios/tags/felica.dart new file mode 100644 index 0000000..a1cecd1 --- /dev/null +++ b/lib/src/nfc_manager_ios/tags/felica.dart @@ -0,0 +1,315 @@ +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +/// The class providing access to FeliCa operations for iOS. +/// +/// Acquire an instance using [from(NfcTag)]. +final class FeliCaIOS { + const FeliCaIOS._( + this._handle, { + required this.currentSystemCode, + required this.currentIDm, + }); + + final String _handle; + + /// DOC: + final Uint8List currentSystemCode; + + /// DOC: + final Uint8List currentIDm; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static FeliCaIOS? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.feliCa; + if (data == null || tech == null) return null; + return FeliCaIOS._( + data.handle, + currentSystemCode: tech.currentSystemCode, + currentIDm: tech.currentIDm, + ); + } + + /// DOC: + Future polling({ + required Uint8List systemCode, + required FeliCaPollingRequestCodeIOS requestCode, + required FeliCaPollingTimeSlotIOS timeSlot, + }) { + return hostApi + .feliCaPolling( + handle: _handle, + systemCode: systemCode, + requestCode: PigeonFeliCaPollingRequestCode.values.byName( + requestCode.name, + ), + timeSlot: PigeonFeliCaPollingTimeSlot.values.byName( + timeSlot.name, + ), + ) + .then((value) => FeliCaPollingResponseIOS( + manufacturerParameter: value.manufacturerParameter, + requestData: value.requestData, + )); + } + + /// DOC: + Future> requestService({ + required List nodeCodeList, + }) { + return hostApi + .feliCaRequestService( + handle: _handle, + nodeCodeList: nodeCodeList, + ) + .then((value) => List.from(value)); + } + + /// DOC: + Future requestResponse() { + return hostApi.feliCaRequestResponse( + handle: _handle, + ); + } + + /// DOC: + Future readWithoutEncryption({ + required List serviceCodeList, + required List blockList, + }) { + return hostApi + .feliCaReadWithoutEncryption( + handle: _handle, + serviceCodeList: serviceCodeList, + blockList: blockList, + ) + .then((value) => FeliCaReadWithoutEncryptionResponseIOS( + statusFlag1: value.statusFlag1, + statusFlag2: value.statusFlag2, + blockData: List.from(value.blockData), + )); + } + + /// DOC: + Future writeWithoutEncryption({ + required List serviceCodeList, + required List blockList, + required List blockData, + }) { + return hostApi + .feliCaWriteWithoutEncryption( + handle: _handle, + serviceCodeList: serviceCodeList, + blockList: blockList, + blockData: blockData, + ) + .then((value) => FeliCaStatusFlagIOS( + statusFlag1: value.statusFlag1, + statusFlag2: value.statusFlag2, + )); + } + + /// DOC: + Future> requestSystemCode() { + return hostApi + .feliCaRequestSystemCode( + handle: _handle, + ) + .then((value) => List.from(value)); + } + + /// DOC: + Future requestServiceV2({ + required List nodeCodeList, + }) { + return hostApi + .feliCaRequestServiceV2( + handle: _handle, + nodeCodeList: nodeCodeList, + ) + .then((value) => FeliCaRequestServiceV2ResponseIOS( + statusFlag1: value.statusFlag1, + statusFlag2: value.statusFlag2, + encryptionIdentifier: value.encryptionIdentifier, + nodeKeyVersionListAes: List.from(value.nodeKeyVersionListAES), + nodeKeyVersionListDes: List.from(value.nodeKeyVersionListDES), + )); + } + + /// DOC: + Future + requestSpecificationVersion() { + return hostApi + .feliCaRequestSpecificationVersion( + handle: _handle, + ) + .then((value) => FeliCaRequestSpecificationVersionResponseIOS( + statusFlag1: value.statusFlag1, + statusFlag2: value.statusFlag2, + basicVersion: value.basicVersion, + optionVersion: value.optionVersion, + )); + } + + /// DOC: + Future resetMode() { + return hostApi + .feliCaResetMode( + handle: _handle, + ) + .then((value) => FeliCaStatusFlagIOS( + statusFlag1: value.statusFlag1, + statusFlag2: value.statusFlag2, + )); + } + + /// DOC: + Future sendFeliCaCommand({ + required Uint8List commandPacket, + }) { + return hostApi.feliCaSendFeliCaCommand( + handle: _handle, + commandPacket: commandPacket, + ); + } +} + +/// DOC: +enum FeliCaPollingRequestCodeIOS { + /// DOC: + noRequest, + + /// DOC: + systemCode, + + /// DOC: + communicationPerformance, +} + +/// DOC: +enum FeliCaPollingTimeSlotIOS { + /// DOC: + max1, + + /// DOC: + max2, + + /// DOC: + max4, + + /// DOC: + max8, + + /// DOC: + max16, +} + +/// DOC: +final class FeliCaPollingResponseIOS { + /// DOC: + @visibleForTesting + const FeliCaPollingResponseIOS({ + required this.manufacturerParameter, + required this.requestData, + }); + + /// DOC: + final Uint8List manufacturerParameter; + + /// DOC: + final Uint8List requestData; +} + +/// DOC: +final class FeliCaStatusFlagIOS { + /// DOC: + @visibleForTesting + const FeliCaStatusFlagIOS({ + required this.statusFlag1, + required this.statusFlag2, + }); + + /// DOC: + final int statusFlag1; + + /// DOC: + final int statusFlag2; +} + +/// DOC: +final class FeliCaReadWithoutEncryptionResponseIOS { + /// DOC: + @visibleForTesting + const FeliCaReadWithoutEncryptionResponseIOS({ + required this.statusFlag1, + required this.statusFlag2, + required this.blockData, + }); + + /// DOC: + final int statusFlag1; + + /// DOC: + final int statusFlag2; + + /// DOC: + final List blockData; +} + +/// DOC: +final class FeliCaRequestServiceV2ResponseIOS { + /// DOC: + @visibleForTesting + const FeliCaRequestServiceV2ResponseIOS({ + required this.statusFlag1, + required this.statusFlag2, + required this.encryptionIdentifier, + required this.nodeKeyVersionListAes, + required this.nodeKeyVersionListDes, + }); + + /// DOC: + final int statusFlag1; + + /// DOC: + final int statusFlag2; + + /// DOC: + final int encryptionIdentifier; + + /// DOC: + final List nodeKeyVersionListAes; + + /// DOC: + final List nodeKeyVersionListDes; +} + +/// DOC: +final class FeliCaRequestSpecificationVersionResponseIOS { + /// DOC: + @visibleForTesting + const FeliCaRequestSpecificationVersionResponseIOS({ + required this.statusFlag1, + required this.statusFlag2, + required this.basicVersion, + required this.optionVersion, + }); + + /// DOC: + final int statusFlag1; + + /// DOC: + final int statusFlag2; + + /// DOC: + final Uint8List basicVersion; + + /// DOC: + final Uint8List optionVersion; +} diff --git a/lib/src/nfc_manager_ios/tags/iso15693.dart b/lib/src/nfc_manager_ios/tags/iso15693.dart new file mode 100644 index 0000000..d8e463c --- /dev/null +++ b/lib/src/nfc_manager_ios/tags/iso15693.dart @@ -0,0 +1,283 @@ +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +/// The class providing access to ISO 15693 operations for iOS. +/// +/// Acquire an instance using [from(NfcTag)]. +final class Iso15693IOS { + const Iso15693IOS._( + this._handle, { + required this.identifier, + required this.icManufacturerCode, + required this.icSerialNumber, + }); + + final String _handle; + + /// DOC: + final Uint8List identifier; + + /// DOC: + final int icManufacturerCode; + + /// DOC: + final Uint8List icSerialNumber; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static Iso15693IOS? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.iso15693; + if (data == null || tech == null) return null; + return Iso15693IOS._( + data.handle, + identifier: tech.identifier, + icManufacturerCode: tech.icManufacturerCode, + icSerialNumber: tech.icSerialNumber, + ); + } + + /// DOC: + Future stayQuiet() { + return hostApi.iso15693StayQuiet( + handle: _handle, + ); + } + + /// DOC: + Future readSingleBlock({ + required List requestFlags, + required int blockNumber, + }) { + return hostApi.iso15693ReadSingleBlock( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + ); + } + + /// DOC: + Future writeSingleBlock({ + required List requestFlags, + required int blockNumber, + required Uint8List dataBlock, + }) { + return hostApi.iso15693WriteSingleBlock( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + dataBlock: dataBlock, + ); + } + + /// DOC: + Future lockBlock({ + required List requestFlags, + required int blockNumber, + }) { + return hostApi.iso15693LockBlock( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + ); + } + + /// DOC: + Future> readMultipleBlocks({ + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + }) { + return hostApi + .iso15693ReadMultipleBlocks( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + numberOfBlocks: numberOfBlocks, + ) + .then((value) => List.from(value)); + } + + /// DOC: + Future writeMultipleBlocks({ + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + required List dataBlocks, + }) { + return hostApi.iso15693WriteMultipleBlocks( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + numberOfBlocks: numberOfBlocks, + dataBlocks: dataBlocks, + ); + } + + /// DOC: + Future select({ + required List requestFlags, + }) { + return hostApi.iso15693Select( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + ); + } + + /// DOC: + Future resetToReady({ + required List requestFlags, + }) { + return hostApi.iso15693ResetToReady( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + ); + } + + /// DOC: + Future writeAfi({ + required List requestFlags, + required int afi, + }) { + return hostApi.iso15693WriteAfi( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + afi: afi, + ); + } + + /// DOC: + Future lockAfi({ + required List requestFlags, + }) { + return hostApi.iso15693LockAfi( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + ); + } + + /// DOC: + Future writeDsfId({ + required List requestFlags, + required int dsfId, + }) { + return hostApi.iso15693WriteDsfId( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + dsfId: dsfId, + ); + } + + /// DOC: + Future lockDsfId({ + required List requestFlags, + }) { + return hostApi.iso15693LockDsfId( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + ); + } + + /// DOC: + Future getSystemInfo({ + required List requestFlags, + }) { + return hostApi + .iso15693GetSystemInfo( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + ) + .then((value) => Iso15693SystemInfoIOS( + applicationFamilyIdentifier: value.applicationFamilyIdentifier, + blockSize: value.blockSize, + dataStorageFormatIdentifier: value.dataStorageFormatIdentifier, + icReference: value.icReference, + totalBlocks: value.totalBlocks, + )); + } + + /// DOC: + Future> getMultipleBlockSecurityStatus({ + required List requestFlags, + required int blockNumber, + required int numberOfBlocks, + }) { + return hostApi + .iso15693GetMultipleBlockSecurityStatus( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + blockNumber: blockNumber, + numberOfBlocks: numberOfBlocks, + ) + .then((value) => List.from(value)); + } + + /// DOC: + Future customCommand({ + required List requestFlags, + required int customCommandCode, + required Uint8List customRequestParameters, + }) { + return hostApi.iso15693CustomCommand( + handle: _handle, + requestFlags: requestFlags.map((e) => e.name).toList(), + customCommandCode: customCommandCode, + customRequestParameters: customRequestParameters, + ); + } +} + +/// DOC: +/// TODO: Add [NFCISO15693SystemInfo.uniqueIdentifier](https://developer.apple.com/documentation/corenfc/nfciso15693systeminfo/3585154-uniqueidentifier). This can be now used with iOS 14.0 or later. +final class Iso15693SystemInfoIOS { + /// DOC: + @visibleForTesting + const Iso15693SystemInfoIOS({ + required this.applicationFamilyIdentifier, + required this.blockSize, + required this.dataStorageFormatIdentifier, + required this.icReference, + required this.totalBlocks, + }); + + /// DOC: + final int applicationFamilyIdentifier; + + /// DOC: + final int blockSize; + + /// DOC: + final int dataStorageFormatIdentifier; + + /// DOC: + final int icReference; + + /// DOC: + final int totalBlocks; +} + +/// DOC: +/// TODO: Add [NFCISO15693RequestFlag.commandSpecificBit8](https://developer.apple.com/documentation/corenfc/nfciso15693requestflag/3551911-commandspecificbit8). This can be now used with iOS 14.0 or later. +enum Iso15693RequestFlagIOS { + /// DOC: + address, + + /// DOC: + dualSubCarriers, + + /// DOC: + highDataRate, + + /// DOC: + option, + + /// DOC: + protocolExtension, + + /// DOC: + select, +} diff --git a/lib/src/nfc_manager_ios/tags/iso7816.dart b/lib/src/nfc_manager_ios/tags/iso7816.dart new file mode 100644 index 0000000..451cc8f --- /dev/null +++ b/lib/src/nfc_manager_ios/tags/iso7816.dart @@ -0,0 +1,117 @@ +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +/// The class providing access to ISO 7816 operations for iOS. +/// +/// Acquire an instance using [from(NfcTag)]. +final class Iso7816IOS { + const Iso7816IOS._( + this._handle, { + required this.initialSelectedAID, + required this.identifier, + required this.historicalBytes, + required this.applicationData, + required this.proprietaryApplicationDataCoding, + }); + + final String _handle; + + /// DOC: + final String initialSelectedAID; + + /// DOC: + final Uint8List identifier; + + /// DOC: + final Uint8List? historicalBytes; + + /// DOC: + final Uint8List? applicationData; + + /// DOC: + final bool proprietaryApplicationDataCoding; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static Iso7816IOS? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.iso7816; + if (data == null || tech == null) return null; + return Iso7816IOS._( + data.handle, + initialSelectedAID: tech.initialSelectedAID, + identifier: tech.identifier, + historicalBytes: tech.historicalBytes, + applicationData: tech.applicationData, + proprietaryApplicationDataCoding: tech.proprietaryApplicationDataCoding, + ); + } + + /// DOC: + Future sendCommand({ + required int instructionClass, + required int instructionCode, + required int p1Parameter, + required int p2Parameter, + required Uint8List data, + required int expectedResponseLength, + }) { + return hostApi + .iso7816SendCommand( + handle: _handle, + apdu: PigeonISO7816APDU( + instructionClass: instructionClass, + instructionCode: instructionCode, + p1Parameter: p1Parameter, + p2Parameter: p2Parameter, + data: data, + expectedResponseLength: expectedResponseLength, + ), + ) + .then((value) => Iso7816ResponseApduIOS( + payload: value.payload, + statusWord1: value.statusWord1, + statusWord2: value.statusWord2, + )); + } + + /// DOC: + Future sendCommandRaw({ + required Uint8List data, + }) { + return hostApi + .iso7816SendCommandRaw( + handle: _handle, + data: data, + ) + .then((value) => Iso7816ResponseApduIOS( + payload: value.payload, + statusWord1: value.statusWord1, + statusWord2: value.statusWord2, + )); + } +} + +/// DOC: +final class Iso7816ResponseApduIOS { + /// DOC: + @visibleForTesting + const Iso7816ResponseApduIOS({ + required this.payload, + required this.statusWord1, + required this.statusWord2, + }); + + /// DOC: + final Uint8List payload; + + /// DOC: + final int statusWord1; + + /// DOC: + final int statusWord2; +} diff --git a/lib/src/nfc_manager_ios/tags/mifare.dart b/lib/src/nfc_manager_ios/tags/mifare.dart new file mode 100644 index 0000000..2849daa --- /dev/null +++ b/lib/src/nfc_manager_ios/tags/mifare.dart @@ -0,0 +1,115 @@ +import 'package:flutter/foundation.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/tags/iso7816.dart'; + +/// The class providing access to MIFARE operations for iOS. +/// +/// Acquire an instance using [from(NfcTag)]. +final class MiFareIOS { + const MiFareIOS._( + this._handle, { + required this.identifier, + required this.mifareFamily, + required this.historicalBytes, + }); + + final String _handle; + + /// DOC: + final Uint8List identifier; + + /// DOC: + final MiFareFamilyIOS mifareFamily; + + /// DOC: + final Uint8List? historicalBytes; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static MiFareIOS? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.miFare; + if (data == null || tech == null) return null; + return MiFareIOS._( + data.handle, + identifier: tech.identifier, + mifareFamily: MiFareFamilyIOS.values.byName(tech.mifareFamily.name), + historicalBytes: tech.historicalBytes, + ); + } + + /// DOC: + Future sendMiFareCommand({ + required Uint8List commandPacket, + }) { + return hostApi.miFareSendMiFareCommand( + handle: _handle, + commandPacket: commandPacket, + ); + } + + /// DOC: + Future sendMiFareIso7816Command({ + required int instructionClass, + required int instructionCode, + required int p1Parameter, + required int p2Parameter, + required Uint8List data, + required int expectedResponseLength, + }) { + return hostApi + .miFareSendMiFareISO7816Command( + handle: _handle, + apdu: PigeonISO7816APDU( + instructionClass: instructionClass, + instructionCode: instructionCode, + p1Parameter: p1Parameter, + p2Parameter: p2Parameter, + data: data, + expectedResponseLength: expectedResponseLength, + ), + ) + // ignore: invalid_use_of_visible_for_testing_member + .then((value) => Iso7816ResponseApduIOS( + payload: value.payload, + statusWord1: value.statusWord1, + statusWord2: value.statusWord2, + )); + } + + /// DOC: + Future sendMiFareIso7816CommandRaw({ + required Uint8List data, + }) { + return hostApi + .miFareSendMiFareISO7816CommandRaw( + handle: _handle, + data: data, + ) + // ignore: invalid_use_of_visible_for_testing_member + .then((value) => Iso7816ResponseApduIOS( + payload: value.payload, + statusWord1: value.statusWord1, + statusWord2: value.statusWord2, + )); + } +} + +/// DOC: +enum MiFareFamilyIOS { + /// DOC: + unknown, + + /// DOC: + ultralight, + + /// DOC: + plus, + + /// DOC: + desfire, +} diff --git a/lib/src/nfc_manager_ios/tags/ndef.dart b/lib/src/nfc_manager_ios/tags/ndef.dart new file mode 100644 index 0000000..3050d27 --- /dev/null +++ b/lib/src/nfc_manager_ios/tags/ndef.dart @@ -0,0 +1,144 @@ +import 'package:flutter/foundation.dart'; +import 'package:ndef_record/ndef_record.dart'; +import 'package:nfc_manager/src/nfc_manager/nfc_manager.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.dart'; +import 'package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart'; + +/// The class providing access to NDEF operations for iOS. +/// +/// Acquire an instance using [from(NfcTag)]. +final class NdefIOS { + const NdefIOS._( + this._handle, { + required this.status, + required this.capacity, + required this.cachedNdefMessage, + }); + + final String _handle; + + /// DOC: + final NdefStatusIOS status; + + /// DOC: + final int capacity; + + /// DOC: + final NdefMessage? cachedNdefMessage; + + /// Creates an instance of this class for the given tag. + /// + /// Returns null if the tag is not compatible. + static NdefIOS? from(NfcTag tag) { + // ignore: invalid_use_of_protected_member + final data = tag.data as PigeonTag?; + final tech = data?.ndef; + if (data == null || tech == null) return null; + return NdefIOS._( + data.handle, + status: NdefStatusIOS.values.byName(tech.status.name), + capacity: tech.capacity, + cachedNdefMessage: tech.cachedNdefMessage == null + ? null + : NdefMessage( + records: tech.cachedNdefMessage!.records + .map((r) => NdefRecord( + typeNameFormat: TypeNameFormat.values.byName( + r!.typeNameFormat.name, + ), + type: r.type, + identifier: r.identifier, + payload: r.payload, + )) + .toList(), + ), + ); + } + + /// DOC: + Future queryNdefStatus() { + return hostApi + .ndefQueryNDEFStatus( + handle: _handle, + ) + .then((value) => QueryNdefStatusResponseIOS( + status: NdefStatusIOS.values.byName(value.status.name), + capacity: value.capacity, + )); + } + + /// DOC: + Future readNdef() { + return hostApi + .ndefReadNDEF( + handle: _handle, + ) + .then((value) => value == null + ? null + : NdefMessage( + records: value.records + .map((r) => NdefRecord( + typeNameFormat: TypeNameFormat.values.byName( + r!.typeNameFormat.name, + ), + type: r.type, + identifier: r.identifier, + payload: r.payload, + )) + .toList(), + )); + } + + /// DOC: + Future writeNdef(NdefMessage message) { + return hostApi.ndefWriteNDEF( + handle: _handle, + message: PigeonNdefMessage( + records: message.records + .map((e) => PigeonNdefPayload( + typeNameFormat: PigeonTypeNameFormat.values.byName( + e.typeNameFormat.name, + ), + type: e.type, + identifier: e.identifier, + payload: e.payload, + )) + .toList(), + )); + } + + /// DOC: + Future writeLock() { + return hostApi.ndefWriteLock( + handle: _handle, + ); + } +} + +/// DOC: +class QueryNdefStatusResponseIOS { + /// DOC: + @visibleForTesting + const QueryNdefStatusResponseIOS({ + required this.status, + required this.capacity, + }); + + /// DOC: + final NdefStatusIOS status; + + /// DOC: + final int capacity; +} + +/// DOC: +enum NdefStatusIOS { + /// DOC: + notSupported, + + /// DOC: + readOnly, + + /// DOC: + readWrite, +} diff --git a/lib/src/platform_tags/felica.dart b/lib/src/platform_tags/felica.dart deleted file mode 100644 index 8655369..0000000 --- a/lib/src/platform_tags/felica.dart +++ /dev/null @@ -1,282 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NFCFeliCaTag API for iOS. -/// -/// Acquire `FeliCa` instance using `FeliCa.from`. -class FeliCa { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `FeliCa.from` are valid. - const FeliCa({ - required NfcTag tag, - required this.currentSystemCode, - required this.currentIDm, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from NFCFeliCaTag#currentSystemCode on iOS. - final Uint8List currentSystemCode; - - /// The value from NFCFeliCaTag#currentIDm on iOS. - final Uint8List currentIDm; - - /// Get an instance of `FeliCa` for the given tag. - /// - /// Returns null if the tag is not compatible with FeliCa. - static FeliCa? from(NfcTag tag) => $GetFeliCa(tag); - - /// Sends the Polling command to the tag. - /// - /// This uses NFCFeliCaTag#polling API on iOS. - Future polling({ - required Uint8List systemCode, - required FeliCaPollingRequestCode requestCode, - required FeliCaPollingTimeSlot timeSlot, - }) async { - return channel.invokeMethod('FeliCa#polling', { - 'handle': _tag.handle, - 'systemCode': systemCode, - 'requestCode': $FeliCaPollingRequestCodeTable[requestCode], - 'timeSlot': $FeliCaPollingTimeSlotTable[timeSlot], - }).then((value) => $GetFeliCaPollingResponse(Map.from(value))); - } - - /// Sends the Request Response command to the tag. - /// - /// This uses NFCFeliCaTag#requestResponse API on iOS. - Future requestResponse() async { - return channel.invokeMethod('FeliCa#requestResponse', { - 'handle': _tag.handle, - }).then((value) => value!); - } - - /// Sends the Request System Code command to the tag. - /// - /// This uses NFCFeliCaTag#requestSystemCode API on iOS. - Future> requestSystemCode() async { - return channel.invokeMethod('FeliCa#requestSystemCode', { - 'handle': _tag.handle, - }).then((value) => List.from(value)); - } - - /// Sends the Request Service command to the tag. - /// - /// This uses NFCFeliCaTag#requestService API on iOS. - Future> requestService({ - required List nodeCodeList, - }) async { - return channel.invokeMethod('FeliCa#requestService', { - 'handle': _tag.handle, - 'nodeCodeList': nodeCodeList, - }).then((value) => List.from(value)); - } - - /// Sends the Request Service V2 command to the tag. - /// - /// This uses NFCFeliCaTag#requestServiceV2 API on iOS. - Future requestServiceV2({ - required List nodeCodeList, - }) async { - return channel.invokeMethod('FeliCa#requestServiceV2', { - 'handle': _tag.handle, - 'nodeCodeList': nodeCodeList, - }).then((value) => $GetFeliCaRequestServiceV2Response(Map.from(value))); - } - - /// Sends the Read Without Encryption command to the tag. - /// - /// This uses NFCFeliCaTag#readWithoutEncryption API on iOS. - Future readWithoutEncryption({ - required List serviceCodeList, - required List blockList, - }) async { - return channel.invokeMethod('FeliCa#readWithoutEncryption', { - 'handle': _tag.handle, - 'serviceCodeList': serviceCodeList, - 'blockList': blockList, - }).then( - (value) => $GetFeliCaReadWithoutEncryptionResponse(Map.from(value))); - } - - /// Sends the Write Without Encryption command to the tag. - /// - /// This uses NFCFeliCaTag#writeWithoutEncryption API on iOS. - Future writeWithoutEncryption({ - required List serviceCodeList, - required List blockList, - required List blockData, - }) async { - return channel.invokeMethod('FeliCa#writeWithoutEncryption', { - 'handle': _tag.handle, - 'serviceCodeList': serviceCodeList, - 'blockList': blockList, - 'blockData': blockData, - }).then((value) => $GetFeliCaStatusFlag(Map.from(value))); - } - - /// Sends the Request Specification Version command to the tag. - /// - /// This uses NFCFeliCaTag#requestSpecificationVersion API on iOS. - Future - requestSpecificationVersion() async { - return channel.invokeMethod('FeliCa#requestSpecificationVersionResponse', { - 'handle': _tag.handle, - }).then((value) => - $GetFeliCaRequestSpecificationVersionResponse(Map.from(value))); - } - - /// Sends the Reset Mode command to the tag. - /// - /// This uses NFCFeliCaTag#resetMode API on iOS. - Future resetMode() async { - return channel.invokeMethod('FeliCa#resetMode', { - 'handle': _tag.handle, - }).then((value) => $GetFeliCaStatusFlag(Map.from(value))); - } - - /// Sends the FeliCa command packet data to the tag. - /// - /// This uses NFCFeliCaTag#sendFeliCaCommand API on iOS. - Future sendFeliCaCommand(Uint8List commandPacket) async { - return channel.invokeMethod('FeliCa#sendFeliCaCommand', { - 'handle': _tag.handle, - 'commandPacket': commandPacket, - }).then((value) => value!); - } -} - -/// The class represents the response of the Polling command. -class FeliCaPollingResponse { - /// Constructs an instance with the given values. - const FeliCaPollingResponse({ - required this.manufacturerParameter, - required this.requestData, - }); - - /// Manufacturer Parameter. - final Uint8List manufacturerParameter; - - /// Request Data. - final Uint8List requestData; -} - -/// The class represents the response of the Request Specification Version command. -class FeliCaRequestSpecificationVersionResponse { - /// Constructs an instance with the given values. - const FeliCaRequestSpecificationVersionResponse({ - required this.statusFlag1, - required this.statusFlag2, - required this.basicVersion, - required this.optionVersion, - }); - - /// Status Flag1. - final int statusFlag1; - - /// Status Flag2. - final int statusFlag2; - - /// Basic Version. - final Uint8List basicVersion; - - /// Option Version. - final Uint8List optionVersion; -} - -/// The class represents the response of the Request Service V2 command. -class FeliCaRequestServiceV2Response { - /// Constructs an instance with the given values. - const FeliCaRequestServiceV2Response({ - required this.statusFlag1, - required this.statusFlag2, - required this.encryptionIdentifier, - required this.nodeKeyVersionListAes, - required this.nodeKeyVersionListDes, - }); - - /// Status Flag1. - final int statusFlag1; - - /// Status Flag2. - final int statusFlag2; - - /// Encryption Identifier. - final int encryptionIdentifier; - - /// Node Key Version List AES. - final List nodeKeyVersionListAes; - - /// Node Key Version List DES. - final List nodeKeyVersionListDes; -} - -/// The class represents the response of the Read Without Encryption command. -class FeliCaReadWithoutEncryptionResponse { - /// Constructs an instance with the given values. - const FeliCaReadWithoutEncryptionResponse({ - required this.statusFlag1, - required this.statusFlag2, - required this.blockData, - }); - - /// Status Flag1. - final int statusFlag1; - - /// Status Flag2. - final int statusFlag2; - - /// Block Data. - final List blockData; -} - -/// The class represents the status flags of the command. -class FeliCaStatusFlag { - /// Constructs an instance with the given values. - const FeliCaStatusFlag({ - required this.statusFlag1, - required this.statusFlag2, - }); - - /// Status Flag1. - final int statusFlag1; - - /// Status Flag2. - final int statusFlag2; -} - -/// Represents PollingRequestCode on iOS. -enum FeliCaPollingRequestCode { - /// Indicates PollingRequestCode#noRequest on iOS. - noRequest, - - /// Indicates PollingRequestCode#systemCode on iOS. - systemCode, - - /// Indicates PollingRequestCode#communicationPerformamce on iOS. - communicationPerformance, -} - -/// Represents PollingTimeSlot on iOS. -enum FeliCaPollingTimeSlot { - /// Indicates PollingTimeSlot#max1 on iOS. - max1, - - /// Indicates PollingTimeSlot#max2 on iOS. - max2, - - /// Indicates PollingTimeSlot#max4 on iOS. - max4, - - /// Indicates PollingTimeSlot#max8 on iOS. - max8, - - /// Indicates PollingTimeSlot#max16 on iOS. - max16, -} diff --git a/lib/src/platform_tags/iso15693.dart b/lib/src/platform_tags/iso15693.dart deleted file mode 100644 index 958af5a..0000000 --- a/lib/src/platform_tags/iso15693.dart +++ /dev/null @@ -1,371 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NFCISO15693Tag API for iOS. -/// -/// Acquire `Iso15693` instance using `Iso15693.from`. -class Iso15693 { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `Iso15693.from` are valid. - const Iso15693({ - required NfcTag tag, - required this.identifier, - required this.icManufacturerCode, - required this.icSerialNumber, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from NFCISO15693Tag#identifier on iOS. - final Uint8List identifier; - - /// The value from NFCISO15693Tag#icManufacturerCode on iOS. - final int icManufacturerCode; - - /// The value from NFCISO15693Tag#icSerialNumber on iOS. - final Uint8List icSerialNumber; - - /// Get an instance of `Iso15693` for the given tag. - /// - /// Returns null if the tag is not compatible with Iso15693. - static Iso15693? from(NfcTag tag) => $GetIso15693(tag); - - /// Sends the Read Single Block command to the tag. - /// - /// This uses NFCISO15693Tag#readSingleBlock API on iOS. - Future readSingleBlock({ - required Set requestFlags, - required int blockNumber, - }) async { - return channel.invokeMethod('Iso15693#readSingleBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber.toUnsigned(8), - }).then((value) => value!); - } - - /// Sends the Write Single Block command to the tag. - /// - /// This uses NFCISO15693Tag#writeSingleBlock API on iOS. - Future writeSingleBlock({ - required Set requestFlags, - required int blockNumber, - required Uint8List dataBlock, - }) async { - return channel.invokeMethod('Iso15693#writeSingleBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber.toUnsigned(8), - 'dataBlock': dataBlock, - }); - } - - /// Sends the Lock Block command to the tag. - /// - /// This uses NFCISO15693Tag#lockBlock API on iOS. - Future lockBlock({ - required Set requestFlags, - required int blockNumber, - }) async { - return channel.invokeMethod('Iso15693#lockBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber.toUnsigned(8), - }); - } - - /// Sends the Read Multiple Blocks command to the tag. - /// - /// This uses NFCISO15693Tag#readMultipleBlocks API on iOS. - Future> readMultipleBlocks({ - required Set requestFlags, - required int blockNumber, - required int numberOfBlocks, - }) async { - return channel.invokeMethod('Iso15693#readMultipleBlocks', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - 'numberOfBlocks': numberOfBlocks, - }).then((value) => List.from(value!)); - } - - /// Sends the Write Multiple Blocks command to the tag. - /// - /// This uses NFCISO15693Tag#writeMultipleBlocks API on iOS. - Future writeMultipleBlocks({ - required Set requestFlags, - required int blockNumber, - required int numberOfBlocks, - required List dataBlocks, - }) async { - return channel.invokeMethod('Iso15693#writeMultipleBlocks', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - 'numberOfBlocks': numberOfBlocks, - 'dataBlocks': dataBlocks, - }); - } - - /// Sends the Get Multiple Block Security Status command to the tag. - /// - /// This uses NFCISO15693Tag#getMultipleBlockSecurityStatus API on iOS. - Future> getMultipleBlockSecurityStatus({ - required Set requestFlags, - required int blockNumber, - required int numberOfBlocks, - }) async { - return channel.invokeMethod('Iso15693#getMultipleBlockSecurityStatus', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - 'numberOfBlocks': numberOfBlocks, - }).then((value) => List.from(value!)); - } - - /// Sends the Write AFI command to the tag. - /// - /// This uses NFCISO15693Tag#writeAFI API on iOS. - Future writeAfi({ - required Set requestFlags, - required int afi, - }) async { - return channel.invokeMethod('Iso15693#writeAfi', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'afi': afi.toUnsigned(8), - }); - } - - /// Sends the Lock AFI command to the tag. - /// - /// This uses NFCISO15693Tag#lockAFI API on iOS. - Future lockAfi({ - required Set requestFlags, - }) async { - return channel.invokeMethod('Iso15693#lockAfi', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - }); - } - - /// Sends the Write DSFID command to the tag. - /// - /// This uses NFCISO15693Tag#writeDSFID API on iOS. - Future writeDsfId({ - required Set requestFlags, - required int dsfId, - }) async { - return channel.invokeMethod('Iso15693#writeDsfId', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'dsfId': dsfId.toUnsigned(8), - }); - } - - /// Sends the Lock DSFID command to the tag. - /// - /// This uses NFCISO15693Tag#lockDSFID API on iOS. - Future lockDsfId({ - required Set requestFlags, - }) async { - return channel.invokeMethod('Iso15693#lockDsfId', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - }); - } - - /// Sends the Reset To Ready command to the tag. - /// - /// This uses NFCISO15693Tag#resetToReady API on iOS. - Future resetToReady({ - required Set requestFlags, - }) async { - return channel.invokeMethod('Iso15693#resetToReady', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - }); - } - - /// Sends the Select command to the tag. - /// - /// This uses NFCISO15693Tag#select API on iOS. - Future select({ - required Set requestFlags, - }) async { - return channel.invokeMethod('Iso15693#select', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - }); - } - - /// Sends the Stay Quiet command to the tag. - /// - /// This uses NFCISO15693Tag#stayQuiet API on iOS. - Future stayQuiet() async { - return channel.invokeMethod('Iso15693#stayQuiet', { - 'handle': _tag.handle, - }); - } - - /// Sends the Extended Read Single Block command to the tag. - /// - /// This uses NFCISO15693Tag#extendedReadSingleBlock API on iOS. - Future extendedReadSingleBlock({ - required Set requestFlags, - required int blockNumber, - }) async { - return channel.invokeMethod('Iso15693#extendedReadSingleBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - }).then((value) => value!); - } - - /// Sends the Extended Write Single Block command to the tag. - /// - /// This uses NFCISO15693Tag#extendedWriteSingleBlock API on iOS. - Future extendedWriteSingleBlock({ - required Set requestFlags, - required int blockNumber, - required Uint8List dataBlock, - }) async { - return channel.invokeMethod('Iso15693#extendedWriteSingleBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - 'dataBlock': dataBlock, - }); - } - - /// Sends the Extended Lock Block command to the tag. - /// - /// This uses NFCISO15693Tag#extendedLockBlock API on iOS. - Future extendedLockBlock({ - required Set requestFlags, - required int blockNumber, - }) async { - return channel.invokeMethod('Iso15693#extendedLockBlock', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - }); - } - - /// Sends the Extended Read Multiple Blocks command to the tag. - /// - /// This uses NFCISO15693Tag#extendedReadMultipleBlocks API on iOS. - Future> extendedReadMultipleBlocks({ - required Set requestFlags, - required int blockNumber, - required int numberOfBlocks, - }) async { - return channel.invokeMethod('Iso15693#extendedReadMultipleBlocks', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'blockNumber': blockNumber, - 'numberOfBlocks': numberOfBlocks, - }).then((value) => List.from(value!)); - } - - /// Sends the Get System Info command to the tag. - /// - /// This uses NFCISO15693Tag#getSystemInfo API on iOS. - Future getSystemInfo({ - required Set requestFlags, - }) async { - return channel.invokeMethod('Iso15693#getSystemInfo', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - }).then((value) => $GetIso15693SystemInfo(Map.from(value!))); - } - - /// Sends the custom command to the tag. - /// - /// This uses NFCISO15693Tag#customCommand API on iOS. - Future customCommand({ - required Set requestFlags, - required int customCommandCode, - required Uint8List customRequestParameters, - }) async { - return channel.invokeMethod('Iso15693#customCommand', { - 'handle': _tag.handle, - 'requestFlags': - requestFlags.map((e) => $Iso15693RequestFlagTable[e]).toList(), - 'customCommandCode': customCommandCode, - 'customRequestParameters': customRequestParameters, - }).then((value) => value!); - } -} - -/// The class represents the response of the Get System Info command. -class Iso15693SystemInfo { - /// Constructs an instance with the given values. - const Iso15693SystemInfo({ - required this.applicationFamilyIdentifier, - required this.blockSize, - required this.dataStorageFormatIdentifier, - required this.icReference, - required this.totalBlocks, - }); - - /// Application Family Identifier. - final int applicationFamilyIdentifier; - - /// Block Size. - final int blockSize; - - /// Data Storage Format Identifier. - final int dataStorageFormatIdentifier; - - // IC Reference. - final int icReference; - - /// Total Blocks. - final int totalBlocks; -} - -/// Represents RequestFlag on iOS. -enum Iso15693RequestFlag { - /// Indicates RequestFlag#address on iOS. - address, - - /// Indicates RequestFlag#dualSubCarriers on iOS. - dualSubCarriers, - - /// Indicates RequestFlag#highDataRate on iOS. - highDataRate, - - /// Indicates RequestFlag#option on iOS. - option, - - /// Indicates RequestFlag#protocolExtension on iOS. - protocolExtension, - - /// Indicates RequestFlag#select on iOS. - select, -} diff --git a/lib/src/platform_tags/iso7816.dart b/lib/src/platform_tags/iso7816.dart deleted file mode 100644 index eb4e89a..0000000 --- a/lib/src/platform_tags/iso7816.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NFCISO7816Tag API for iOS. -/// -/// Acquire `Iso7816` instance using `Iso7816.from`. -class Iso7816 { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `Iso7816.from` are valid. - const Iso7816({ - required NfcTag tag, - required this.identifier, - required this.initialSelectedAID, - required this.historicalBytes, - required this.applicationData, - required this.proprietaryApplicationDataCoding, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from NFCISO7816Tag#identifier on iOS. - final Uint8List identifier; - - /// The value from NFCISO7816Tag#initialSelectedAID on iOS. - final String initialSelectedAID; - - /// The value from NFCISO7816Tag#historicalBytes on iOS. - final Uint8List? historicalBytes; - - /// The value from NFCISO7816Tag#applicationData on iOS. - final Uint8List? applicationData; - - /// The value from NFCISO7816Tag#proprietaryApplicationDataCoding on iOS. - final bool proprietaryApplicationDataCoding; - - /// Get an instance of `Iso7816` for the given tag. - /// - /// Returns null if the tag is not compatible with Iso7816. - static Iso7816? from(NfcTag tag) => $GetIso7816(tag); - - /// Sends the APDU to the tag. - /// - /// This uses NFCISO7816Tag#sendCommand API on iOS. - Future sendCommand({ - required int instructionClass, - required int instructionCode, - required int p1Parameter, - required int p2Parameter, - required Uint8List data, - required int expectedResponseLength, - }) async { - return channel.invokeMethod('Iso7816#sendCommand', { - 'handle': _tag.handle, - 'instructionClass': instructionClass, - 'instructionCode': instructionCode, - 'p1Parameter': p1Parameter, - 'p2Parameter': p2Parameter, - 'data': data, - 'expectedResponseLength': expectedResponseLength, - }).then((value) => $GetIso7816ResponseApdu(Map.from(value))); - } - - /// Sends the APDU to the tag. - /// - /// This uses NFCISO7816Tag#sendCommand API on iOS. - Future sendCommandRaw(Uint8List data) async { - return channel.invokeMethod('Iso7816#sendCommandRaw', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => $GetIso7816ResponseApdu(Map.from(value))); - } -} - -/// The class represents the response APDU. -class Iso7816ResponseApdu { - /// Constructs an instance with the given values. - const Iso7816ResponseApdu({ - required this.payload, - required this.statusWord1, - required this.statusWord2, - }); - - /// Payload. - final Uint8List payload; - - /// Status Word1. - final int statusWord1; - - /// Status Word2. - final int statusWord2; -} diff --git a/lib/src/platform_tags/iso_dep.dart b/lib/src/platform_tags/iso_dep.dart deleted file mode 100644 index 4032593..0000000 --- a/lib/src/platform_tags/iso_dep.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to IsoDep API for Android. -/// -/// Acquire `IsoDep` instance using `IsoDep.from`. -class IsoDep { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `IsoDep.from` are valid. - const IsoDep({ - required NfcTag tag, - required this.identifier, - required this.hiLayerResponse, - required this.historicalBytes, - required this.isExtendedLengthApduSupported, - required this.maxTransceiveLength, - required this.timeout, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from IsoDep#hiLayerResponse on Android. - final Uint8List? hiLayerResponse; - - /// The value from IsoDep#historicalBytes on Android. - final Uint8List? historicalBytes; - - /// The value from IsoDep#isExtendedLengthApduSupported on Android. - final bool isExtendedLengthApduSupported; - - /// The value from IsoDep#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// The value from IsoDep#timeout on Android. - final int timeout; - - /// Get an instance of `IsoDep` for the given tag. - /// - /// Returns null if the tag is not compatible with IsoDep. - static IsoDep? from(NfcTag tag) => $GetIsoDep(tag); - - /// Sends the IsoDep command to the tag. - /// - /// This uses IsoDep#transceive API on Android. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('IsoDep#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/mifare.dart b/lib/src/platform_tags/mifare.dart deleted file mode 100644 index 3b8cc2b..0000000 --- a/lib/src/platform_tags/mifare.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; -import './iso7816.dart'; - -/// The class provides access to NFCMiFareTag API for iOS. -/// -/// Acquire `MiFare` instance using `MiFare.from`. -class MiFare { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `MiFare.from` are valid. - const MiFare({ - required NfcTag tag, - required this.mifareFamily, - required this.identifier, - required this.historicalBytes, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from NFCMiFareTag#mifareFamily on iOS. - final MiFareFamily mifareFamily; - - /// The value from NFCMiFareTag#identifier on iOS. - final Uint8List identifier; - - /// The value from NFCMiFareTag#historicalBytes on iOS. - final Uint8List? historicalBytes; - - /// Get an instance of `MiFare` for the given tag. - /// - /// Returns null if the tag is not compatible with MiFare. - static MiFare? from(NfcTag tag) => $GetMiFare(tag); - - /// Sends the native MiFare command to the tag. - /// - /// This uses NFCMiFareTag#sendMiFareCommand API on iOS. - Future sendMiFareCommand(Uint8List commandPacket) async { - return channel.invokeMethod('MiFare#sendMiFareCommand', { - 'handle': _tag.handle, - 'commandPacket': commandPacket, - }).then((value) => value!); - } - - /// Sends the ISO7816 APDU to the tag. - /// - /// This uses NFCMiFareTag#sendMiFareISO7816Command API on iOS. - Future sendMiFareIso7816Command({ - required int instructionClass, - required int instructionCode, - required int p1Parameter, - required int p2Parameter, - required Uint8List data, - required int expectedResponseLength, - }) async { - return channel.invokeMethod('MiFare#sendMiFareIso7816Command', { - 'handle': _tag.handle, - 'instructionClass': instructionClass, - 'instructionCode': instructionCode, - 'p1Parameter': p1Parameter, - 'p2Parameter': p2Parameter, - 'data': data, - 'expectedResponseLength': expectedResponseLength, - }).then((value) => $GetIso7816ResponseApdu(Map.from(value))); - } - - /// Sends the ISO7816 APDU to the tag. - /// - /// This uses NFCMiFareTag#sendMiFareISO7816Command API on iOS. - Future sendMiFareIso7816CommandRaw( - Uint8List data) async { - return channel.invokeMethod('MiFare#sendMiFareIso7816CommandRaw', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => $GetIso7816ResponseApdu(Map.from(value))); - } -} - -/// Represents NFCMiFareFamily on iOS. -enum MiFareFamily { - /// Indicates NFCMiFareFamily#unknown on iOS. - unknown, - - /// Indicates NFCMiFareFamily#ultralight on iOS. - ultralight, - - /// Indicates NFCMiFareFamily#plus on iOS. - plus, - - /// Indicates NFCMiFareFamily#desfire on iOS. - desfire, -} diff --git a/lib/src/platform_tags/mifare_classic.dart b/lib/src/platform_tags/mifare_classic.dart deleted file mode 100644 index 361cdfd..0000000 --- a/lib/src/platform_tags/mifare_classic.dart +++ /dev/null @@ -1,173 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to MifareClassic API for Android. -/// -/// Acquire `MifareClassic` instance using `MifareClassic.from`. -class MifareClassic { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `MifareClassic.from` are valid. - const MifareClassic({ - required NfcTag tag, - required this.identifier, - required this.type, - required this.blockCount, - required this.sectorCount, - required this.size, - required this.maxTransceiveLength, - required this.timeout, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from MifareClassic#type on Android. - final int type; - - /// The value from MifareClassic#blockCount on Android. - final int blockCount; - - /// The value from MifareClassic#sectorCount on Android. - final int sectorCount; - - /// The value from MifareClassic#size on Android. - final int size; - - /// The value from MifareClassic#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// The value from MifareClassic#timeout on Android. - final int timeout; - - /// Get an instance of `MifareClassic` for the given tag. - /// - /// Returns null if the tag is not compatible with MifareClassic. - static MifareClassic? from(NfcTag tag) => $GetMifareClassic(tag); - - /// Sends the Authenticate Sector With Key A command to the tag. - /// - /// This uses MifareClassic#authenticateSectorWithKeyA API on Android. - Future authenticateSectorWithKeyA({ - required int sectorIndex, - required Uint8List key, - }) async { - return channel.invokeMethod('MifareClassic#authenticateSectorWithKeyA', { - 'handle': _tag.handle, - 'sectorIndex': sectorIndex, - 'key': key, - }).then((value) => value!); - } - - /// Sends the Authenticate Sector With Key B command to the tag. - /// - /// This uses MifareClassic#authenticateSectorWithKeyB API on Android. - Future authenticateSectorWithKeyB({ - required int sectorIndex, - required Uint8List key, - }) async { - return channel.invokeMethod('MifareClassic#authenticateSectorWithKeyB', { - 'handle': _tag.handle, - 'sectorIndex': sectorIndex, - 'key': key, - }).then((value) => value!); - } - - /// Sends the Increment command to the tag. - /// - /// This uses MifareClassic#increment API on Android. - Future increment({ - required int blockIndex, - required int value, - }) async { - return channel.invokeMethod('MifareClassic#increment', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - 'value': value, - }); - } - - /// Sends the Decrement command to the tag. - /// - /// This uses MifareClassic#decrement API on Android. - Future decrement({ - required int blockIndex, - required int value, - }) async { - return channel.invokeMethod('MifareClassic#decrement', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - 'value': value, - }); - } - - /// Sends the Read Block command to the tag. - /// - /// This uses MifareClassic#readBlock API on Android. - Future readBlock({ - required int blockIndex, - }) async { - return channel.invokeMethod('MifareClassic#readBlock', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - }).then((value) => value!); - } - - /// Sends the Write Block command to the tag. - /// - /// This uses MifareClassic#writeBlock API on Android. - Future writeBlock({ - required int blockIndex, - required Uint8List data, - }) async { - return channel.invokeMethod('MifareClassic#writeBlock', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - 'data': data, - }); - } - - /// Sends the Restore command to the tag. - /// - /// This uses MifareClassic#restore API on Android. - Future restore({ - required int blockIndex, - }) async { - return channel.invokeMethod('MifareClassic#restore', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - }); - } - - /// Sends the Transfer command to the tag. - /// - /// This uses MifareClassic#transfer API on Android. - Future transfer({ - required int blockIndex, - }) async { - return channel.invokeMethod('MifareClassic#transfer', { - 'handle': _tag.handle, - 'blockIndex': blockIndex, - }); - } - - /// Sends the NfcA command to the tag. - /// - /// This uses MifareClassic#transceive API on Android. - /// This is equivalent to obtaining via `NfcA.from` this tag and calling `NfcA#transceive`. - Future transceive({ - required int data, - }) async { - return channel.invokeMethod('MifareClassic#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/mifare_ultralight.dart b/lib/src/platform_tags/mifare_ultralight.dart deleted file mode 100644 index b28a072..0000000 --- a/lib/src/platform_tags/mifare_ultralight.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to MifareUltralight API for Android. -/// -/// Acquire `MifareUltralight` instance using `MifareUltralight.from`. -class MifareUltralight { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `MifareUltralight.from` are valid. - const MifareUltralight({ - required NfcTag tag, - required this.identifier, - required this.type, - required this.maxTransceiveLength, - required this.timeout, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from MifareUltralight#type on Android. - final int type; - - /// The value from MifareUltralight#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// The value from MifareUltralight#timeout on Android. - final int timeout; - - /// Get an instance of `MifareUltralight` for the given tag. - /// - /// Returns null if the tag is not compatible with MifareUltralight. - static MifareUltralight? from(NfcTag tag) => $GetMifareUltralight(tag); - - /// Sends the Read Pages command to the tag. - /// - /// This uses MifareUltralight#readPages API on Android. - Future readPages({ - required int pageOffset, - }) async { - return channel.invokeMethod('MifareUltralight#readPages', { - 'handle': _tag.handle, - 'pageOffset': pageOffset, - }).then((value) => value!); - } - - /// Sends the Write Page command to the tag. - /// - /// This uses MifareUltralight#writePage API on Android. - Future writePage({ - required int pageOffset, - required Uint8List data, - }) async { - return channel.invokeMethod('MifareUltralight#writePage', { - 'handle': _tag.handle, - 'pageOffset': pageOffset, - 'data': data, - }); - } - - /// Sends the NfcA command to the tag. - /// - /// This uses MifareUltralight#transceive API on Android. - /// This is equivalent to obtaining via `NfcA.from` this tag and calling `NfcA#transceive`. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('MifareUltralight#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/ndef_formatable.dart b/lib/src/platform_tags/ndef_formatable.dart deleted file mode 100644 index ce8116a..0000000 --- a/lib/src/platform_tags/ndef_formatable.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../nfc_manager/nfc_ndef.dart'; -import '../translator.dart'; - -/// The class provides access to NdefFormatable API for Android. -/// -/// Acquire `NdefFormatable` instance using `NdefFormatable.from`. -class NdefFormatable { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `NdefFormatable.from` are valid. - const NdefFormatable({ - required NfcTag tag, - required this.identifier, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// Get an instance of `NdefFormatable` for the given tag. - /// - /// Returns null if the tag is not NDEF formatable. - static NdefFormatable? from(NfcTag tag) => $GetNdefFormatable(tag); - - /// Format the tag as NDEF, and write the given NDEF message. - /// - /// This uses NdefFormatable#format API on Android. - Future format(NdefMessage firstMessage) async { - return channel.invokeMethod('NdefFormatable#format', { - 'handle': _tag.handle, - 'firstMessage': $GetNdefMessageMap(firstMessage), - }); - } - - /// Format the tag as NDEF, write the given NDEF message, and make read-only. - /// - /// This uses NdefFormatable#formatReadOnly API on Android. - Future formatReadOnly(NdefMessage firstMessage) async { - return channel.invokeMethod('NdefFormatable#formatReadOnly', { - 'handle': _tag.handle, - 'firstMessage': $GetNdefMessageMap(firstMessage), - }); - } -} diff --git a/lib/src/platform_tags/nfc_a.dart b/lib/src/platform_tags/nfc_a.dart deleted file mode 100644 index 1403317..0000000 --- a/lib/src/platform_tags/nfc_a.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NfcA API for Android. -/// -/// Acquire `NfcA` instance using `NfcA.from`. -class NfcA { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `NfcA.from` are valid. - const NfcA({ - required NfcTag tag, - required this.identifier, - required this.atqa, - required this.sak, - required this.maxTransceiveLength, - required this.timeout, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from NfcA#atqa on Android. - final Uint8List atqa; - - /// The value from NfcA#sak on Android. - final int sak; - - /// The value from NfcA#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// The value from NfcA#timeout on Android. - final int timeout; - - /// Get an instance of `NfcA` for the given tag. - /// - /// Returns null if the tag is not compatible with NfcA. - static NfcA? from(NfcTag tag) => $GetNfcA(tag); - - /// Sends the NfcA command to the tag. - /// - /// This uses NfcA#transceive API on Android. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('NfcA#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/nfc_b.dart b/lib/src/platform_tags/nfc_b.dart deleted file mode 100644 index 3fe37ce..0000000 --- a/lib/src/platform_tags/nfc_b.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NfcB API for Android. -/// -/// Acquire `NfcB` instance using `NfcB.from`. -class NfcB { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `NfcB.from` are valid. - const NfcB({ - required NfcTag tag, - required this.identifier, - required this.applicationData, - required this.protocolInfo, - required this.maxTransceiveLength, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from NfcB#applicationData on Android. - final Uint8List applicationData; - - /// The value from NfcB#protocolInfo on Android. - final Uint8List protocolInfo; - - /// The value from NfcB#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// Get an instance of `NfcB` for the given tag. - /// - /// Returns null if the tag is not compatible with NfcB. - static NfcB? from(NfcTag tag) => $GetNfcB(tag); - - /// Sends the NfcB command to the tag. - /// - /// This uses NfcB#transceive API on Android. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('NfcB#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/nfc_f.dart b/lib/src/platform_tags/nfc_f.dart deleted file mode 100644 index 1304683..0000000 --- a/lib/src/platform_tags/nfc_f.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NfcF API for Android. -/// -/// Acquire `NfcF` instance using `NfcF.from`. -class NfcF { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `NfcF.from` are valid. - const NfcF({ - required NfcTag tag, - required this.identifier, - required this.manufacturer, - required this.systemCode, - required this.maxTransceiveLength, - required this.timeout, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from NfcF#manufacturer on Android. - final Uint8List manufacturer; - - /// The value from NfcF#systemCode on Android. - final Uint8List systemCode; - - /// The value from NfcF#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// The value from NfcF#timeout on Android. - final int timeout; - - /// Get an instance of `NfcF` for the given tag. - /// - /// Returns null if the tag is not compatible with NfcF. - static NfcF? from(NfcTag tag) => $GetNfcF(tag); - - /// Sends the NfcF command to the tag. - /// - /// This uses NfcF#transceive API on Android. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('NfcF#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/platform_tags/nfc_v.dart b/lib/src/platform_tags/nfc_v.dart deleted file mode 100644 index 6b93579..0000000 --- a/lib/src/platform_tags/nfc_v.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'dart:typed_data'; - -import '../channel.dart'; -import '../nfc_manager/nfc_manager.dart'; -import '../translator.dart'; - -/// The class provides access to NfcV API for Android. -/// -/// Acquire `NfcV` instance using `NfcV.from`. -class NfcV { - /// Constructs an instance with the given values for testing. - /// - /// The instances constructs by this way are not valid in the production environment. - /// Only instances obtained from the `NfcV.from` are valid. - const NfcV({ - required NfcTag tag, - required this.identifier, - required this.dsfId, - required this.responseFlags, - required this.maxTransceiveLength, - }) : _tag = tag; - - // _tag - final NfcTag _tag; - - /// The value from Tag#id on Android. - final Uint8List identifier; - - /// The value from NfcV#dsfId on Android. - final int dsfId; - - /// The value from NfcV#responseFlags on Android. - final int responseFlags; - - /// The value from NfcV#maxTransceiveLength on Android. - final int maxTransceiveLength; - - /// Get an instance of `NfcV` for the given tag. - /// - /// Returns null if the tag is not compatible with NfcV. - static NfcV? from(NfcTag tag) => $GetNfcV(tag); - - /// Sends the NfcV command to the tag. - /// - /// This uses NfcV#transceive API on Android. - Future transceive({ - required Uint8List data, - }) async { - return channel.invokeMethod('NfcV#transceive', { - 'handle': _tag.handle, - 'data': data, - }).then((value) => value!); - } -} diff --git a/lib/src/translator.dart b/lib/src/translator.dart deleted file mode 100644 index 8ab13cb..0000000 --- a/lib/src/translator.dart +++ /dev/null @@ -1,337 +0,0 @@ -import 'dart:typed_data'; - -import './nfc_manager/nfc_manager.dart'; -import './nfc_manager/nfc_ndef.dart'; -import './platform_tags/felica.dart'; -import './platform_tags/iso7816.dart'; -import './platform_tags/iso15693.dart'; -import './platform_tags/iso_dep.dart'; -import './platform_tags/mifare.dart'; -import './platform_tags/mifare_classic.dart'; -import './platform_tags/mifare_ultralight.dart'; -import './platform_tags/ndef_formatable.dart'; -import './platform_tags/nfc_a.dart'; -import './platform_tags/nfc_b.dart'; -import './platform_tags/nfc_f.dart'; -import './platform_tags/nfc_v.dart'; - -const Map $NfcPollingOptionTable = { - NfcPollingOption.iso14443: 'iso14443', - NfcPollingOption.iso15693: 'iso15693', - NfcPollingOption.iso18092: 'iso18092', -}; - -const Map $NfcErrorTypeTable = { - NfcErrorType.sessionTimeout: 'sessionTimeout', - NfcErrorType.systemIsBusy: 'systemIsBusy', - NfcErrorType.userCanceled: 'userCanceled', - NfcErrorType.unknown: 'unknown', -}; - -const Map $NdefTypeNameFormatTable = { - NdefTypeNameFormat.empty: 0x00, - NdefTypeNameFormat.nfcWellknown: 0x01, - NdefTypeNameFormat.media: 0x02, - NdefTypeNameFormat.absoluteUri: 0x03, - NdefTypeNameFormat.nfcExternal: 0x04, - NdefTypeNameFormat.unknown: 0x05, - NdefTypeNameFormat.unchanged: 0x06, -}; - -const Map $FeliCaPollingRequestCodeTable = { - FeliCaPollingRequestCode.noRequest: 0x00, - FeliCaPollingRequestCode.systemCode: 0x01, - FeliCaPollingRequestCode.communicationPerformance: 0x02, -}; - -const Map $FeliCaPollingTimeSlotTable = { - FeliCaPollingTimeSlot.max1: 0x00, - FeliCaPollingTimeSlot.max2: 0x01, - FeliCaPollingTimeSlot.max4: 0x03, - FeliCaPollingTimeSlot.max8: 0x07, - FeliCaPollingTimeSlot.max16: 0x0F, -}; - -const Map $Iso15693RequestFlagTable = { - Iso15693RequestFlag.address: 'address', - Iso15693RequestFlag.dualSubCarriers: 'dualSubCarriers', - Iso15693RequestFlag.highDataRate: 'highDataRate', - Iso15693RequestFlag.option: 'option', - Iso15693RequestFlag.protocolExtension: 'protocolExtension', - Iso15693RequestFlag.select: 'select', -}; - -const Map $MiFareFamilyTable = { - MiFareFamily.unknown: 1, - MiFareFamily.ultralight: 2, - MiFareFamily.plus: 3, - MiFareFamily.desfire: 4, -}; - -NfcTag $GetNfcTag(Map arg) { - return NfcTag( - handle: arg.remove('handle'), - data: arg, - ); -} - -NfcError $GetNfcError(Map arg) { - return NfcError( - type: $NfcErrorTypeTable.values.contains(arg['type']) - ? $NfcErrorTypeTable.entries - .firstWhere((e) => e.value == arg['type']) - .key - : NfcErrorType.unknown, - message: arg['message'], - details: arg['details'], - ); -} - -NdefMessage $GetNdefMessage(Map arg) { - return NdefMessage((arg['records'] as Iterable) - .map((e) => NdefRecord( - typeNameFormat: $NdefTypeNameFormatTable.entries - .firstWhere((ee) => ee.value == e['typeNameFormat']) - .key, - type: e['type'], - identifier: e['identifier'], - payload: e['payload'], - )) - .toList()); -} - -Map $GetNdefMessageMap(NdefMessage arg) { - return { - 'records': arg.records - .map((e) => { - 'typeNameFormat': $NdefTypeNameFormatTable[e.typeNameFormat], - 'type': e.type, - 'identifier': e.identifier, - 'payload': e.payload, - }) - .toList() - }; -} - -FeliCaPollingResponse $GetFeliCaPollingResponse(Map arg) { - return FeliCaPollingResponse( - manufacturerParameter: arg['manufacturerParameter'], - requestData: arg['requestData'], - ); -} - -FeliCaRequestServiceV2Response $GetFeliCaRequestServiceV2Response( - Map arg) { - return FeliCaRequestServiceV2Response( - statusFlag1: arg['statusFlag1'], - statusFlag2: arg['statusFlag2'], - encryptionIdentifier: arg['encryptionIdentifier'], - nodeKeyVersionListAes: List.from(arg['nodeKeyVersionListAes']), - nodeKeyVersionListDes: List.from(arg['nodeKeyVersionListDes']), - ); -} - -FeliCaReadWithoutEncryptionResponse $GetFeliCaReadWithoutEncryptionResponse( - Map arg) { - return FeliCaReadWithoutEncryptionResponse( - statusFlag1: arg['statusFlag1'], - statusFlag2: arg['statusFlag2'], - blockData: List.from(arg['blockData']), - ); -} - -FeliCaStatusFlag $GetFeliCaStatusFlag(Map arg) { - return FeliCaStatusFlag( - statusFlag1: arg['statusFlag1'], - statusFlag2: arg['statusFlag2'], - ); -} - -FeliCaRequestSpecificationVersionResponse - $GetFeliCaRequestSpecificationVersionResponse(Map arg) { - return FeliCaRequestSpecificationVersionResponse( - statusFlag1: arg['statusFlag1'], - statusFlag2: arg['statusFlag2'], - basicVersion: arg['basicVersion'], - optionVersion: arg['optionVersion'], - ); -} - -Iso15693SystemInfo $GetIso15693SystemInfo(Map arg) { - return Iso15693SystemInfo( - dataStorageFormatIdentifier: arg['dataStorageFormatIdentifier'], - applicationFamilyIdentifier: arg['applicationFamilyIdentifier'], - blockSize: arg['blockSize'], - totalBlocks: arg['totalBlocks'], - icReference: arg['icReference'], - ); -} - -Iso7816ResponseApdu $GetIso7816ResponseApdu(Map arg) { - return Iso7816ResponseApdu( - payload: arg['payload'], - statusWord1: arg['statusWord1'], - statusWord2: arg['statusWord2'], - ); -} - -Ndef? $GetNdef(NfcTag arg) { - if (arg.data['ndef'] == null) return null; - final data = Map.from(arg.data['ndef']); - return Ndef( - tag: arg, - isWritable: data.remove('isWritable'), - maxSize: data.remove('maxSize'), - cachedMessage: data['cachedMessage'] == null - ? null - : $GetNdefMessage( - Map.from(data.remove('cachedMessage'))), - additionalData: data, - ); -} - -FeliCa? $GetFeliCa(NfcTag arg) { - if (arg.data['felica'] == null) return null; - final data = Map.from(arg.data['felica']); - return FeliCa( - tag: arg, - currentSystemCode: data['currentSystemCode'], - currentIDm: data['currentIDm'], - ); -} - -Iso7816? $GetIso7816(NfcTag arg) { - if (arg.data['iso7816'] == null) return null; - final data = Map.from(arg.data['iso7816']); - return Iso7816( - tag: arg, - identifier: data['identifier'], - historicalBytes: data['historicalBytes'], - applicationData: data['applicationData'], - initialSelectedAID: data['initialSelectedAID'], - proprietaryApplicationDataCoding: data['proprietaryApplicationDataCoding'], - ); -} - -Iso15693? $GetIso15693(NfcTag arg) { - if (arg.data['iso15693'] == null) return null; - final data = Map.from(arg.data['iso15693']); - return Iso15693( - tag: arg, - identifier: data['identifier'], - icManufacturerCode: data['icManufacturerCode'], - icSerialNumber: data['icSerialNumber'], - ); -} - -MiFare? $GetMiFare(NfcTag arg) { - if (arg.data['mifare'] == null) return null; - final data = Map.from(arg.data['mifare']); - return MiFare( - tag: arg, - identifier: data['identifier'], - mifareFamily: $MiFareFamilyTable.entries - .firstWhere((e) => e.value == data['mifareFamily']) - .key, - historicalBytes: data['historicalBytes']); -} - -NfcA? $GetNfcA(NfcTag arg) { - if (arg.data['nfca'] == null) return null; - final data = Map.from(arg.data['nfca']); - return NfcA( - tag: arg, - identifier: data['identifier'], - atqa: data['atqa'], - sak: data['sak'], - maxTransceiveLength: data['maxTransceiveLength'], - timeout: data['timeout'], - ); -} - -NfcB? $GetNfcB(NfcTag arg) { - if (arg.data['nfcb'] == null) return null; - final data = Map.from(arg.data['nfcb']); - return NfcB( - tag: arg, - identifier: data['identifier'], - applicationData: data['applicationData'], - protocolInfo: data['protocolInfo'], - maxTransceiveLength: data['maxTransceiveLength'], - ); -} - -NfcF? $GetNfcF(NfcTag arg) { - if (arg.data['nfcf'] == null) return null; - final data = Map.from(arg.data['nfcf']); - return NfcF( - tag: arg, - identifier: data['identifier'], - manufacturer: data['manufacturer'], - systemCode: data['systemCode'], - maxTransceiveLength: data['maxTransceiveLength'], - timeout: data['timeout'], - ); -} - -NfcV? $GetNfcV(NfcTag arg) { - if (arg.data['nfcv'] == null) return null; - final data = Map.from(arg.data['nfcv']); - return NfcV( - tag: arg, - identifier: data['identifier'], - dsfId: data['dsfId'], - responseFlags: data['responseFlags'], - maxTransceiveLength: data['maxTransceiveLength'], - ); -} - -IsoDep? $GetIsoDep(NfcTag arg) { - if (arg.data['isodep'] == null) return null; - final data = Map.from(arg.data['isodep']); - return IsoDep( - tag: arg, - identifier: data['identifier'], - hiLayerResponse: data['hiLayerResponse'], - historicalBytes: data['historicalBytes'], - isExtendedLengthApduSupported: data['isExtendedLengthApduSupported'], - maxTransceiveLength: data['maxTransceiveLength'], - timeout: data['timeout'], - ); -} - -MifareClassic? $GetMifareClassic(NfcTag arg) { - if (arg.data['mifareclassic'] == null) return null; - final data = Map.from(arg.data['mifareclassic']); - return MifareClassic( - tag: arg, - identifier: data['identifier'], - type: data['type'], - blockCount: data['blockCount'], - sectorCount: data['sectorCount'], - size: data['size'], - maxTransceiveLength: data['maxTransceiveLength'], - timeout: data['timeout'], - ); -} - -MifareUltralight? $GetMifareUltralight(NfcTag arg) { - if (arg.data['mifareultralight'] == null) return null; - final data = Map.from(arg.data['mifareultralight']); - return MifareUltralight( - tag: arg, - identifier: data['identifier'], - type: data['type'], - maxTransceiveLength: data['maxTransceiveLength'], - timeout: data['timeout'], - ); -} - -NdefFormatable? $GetNdefFormatable(NfcTag arg) { - if (arg.data['ndefformatable'] == null) return null; - final data = Map.from(arg.data['ndefformatable']); - return NdefFormatable( - tag: arg, - identifier: data['identifier'], - ); -} diff --git a/pigeon/android.dart b/pigeon/android.dart new file mode 100644 index 0000000..c18f0da --- /dev/null +++ b/pigeon/android.dart @@ -0,0 +1,231 @@ +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon(PigeonOptions( + dartOut: 'lib/src/nfc_manager_android/pigeon.g.dart', + kotlinOut: 'android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt', + kotlinOptions: KotlinOptions(package: 'dev.flutter.plugins.nfcmanager'), +)) + +@FlutterApi() +abstract final class PigeonFlutterApi { + void onTagDiscovered(PigeonTag tag); + void onAdapterStateChanged(int state); +} + +@HostApi() +abstract final class PigeonHostApi { + bool nfcAdapterIsEnabled(); + bool nfcAdapterIsSecureNfcEnabled(); + bool nfcAdapterIsSecureNfcSupported(); + void nfcAdapterEnableReaderMode({required List flags}); + void nfcAdapterDisableReaderMode(); + void nfcAdapterEnableForegroundDispatch(); + void nfcAdapterDisableForegroundDispatch(); + PigeonNdefMessage? ndefGetNdefMessage({required String handle}); + void ndefWriteNdefMessage({required String handle, required PigeonNdefMessage message}); + bool ndefMakeReadOnly({required String handle}); + int nfcAGetMaxTransceiveLength({required String handle}); + int nfcAGetTimeout({required String handle}); + void nfcASetTimeout({required String handle, required int timeout}); + Uint8List nfcATransceive({required String handle, required Uint8List bytes}); + int nfcBGetMaxTransceiveLength({required String handle}); + Uint8List nfcBTransceive({required String handle, required Uint8List bytes}); + int nfcFGetMaxTransceiveLength({required String handle}); + int nfcFGetTimeout({required String handle}); + void nfcFSetTimeout({required String handle, required int timeout}); + Uint8List nfcFTransceive({required String handle, required Uint8List bytes}); + int nfcVGetMaxTransceiveLength({required String handle}); + Uint8List nfcVTransceive({required String handle, required Uint8List bytes}); + int isoDepGetMaxTransceiveLength({required String handle}); + int isoDepGetTimeout({required String handle}); + void isoDepSetTimeout({required String handle, required int timeout}); + Uint8List isoDepTransceive({required String handle, required Uint8List bytes}); + int mifareClassicGetMaxTransceiveLength({required String handle}); + int mifareClassicGetTimeout({required String handle}); + void mifareClassicSetTimeout({required String handle, required int timeout}); + int mifareClassicBlockToSector({required String handle, required int blockIndex}); + int mifareClassicGetBlockCountInSector({required String handle, required int sectorIndex}); + int mifareClassicSectorToBlock({required String handle, required int sectorIndex}); + bool mifareClassicAuthenticateSectorWithKeyA({required String handle, required int sectorIndex, required Uint8List key}); + bool mifareClassicAuthenticateSectorWithKeyB({required String handle, required int sectorIndex, required Uint8List key}); + void mifareClassicIncrement({required String handle, required int blockIndex, required int value}); + void mifareClassicDecrement({required String handle, required int blockIndex, required int value}); + Uint8List mifareClassicReadBlock({required String handle, required int blockIndex}); + void mifareClassicWriteBlock({required String handle, required int blockIndex, required Uint8List data}); + void mifareClassicRestore({required String handle, required int blockIndex}); + void mifareClassicTransfer({required String handle, required int blockIndex}); + Uint8List mifareClassicTransceive({required String handle, required Uint8List bytes}); + int mifareUltralightGetMaxTransceiveLength({required String handle}); + int mifareUltralightGetTimeout({required String handle}); + void mifareUltralightSetTimeout({required String handle, required int timeout}); + Uint8List mifareUltralightReadPages({required String handle, required int pageOffset}); + void mifareUltralightWritePage({required String handle, required int pageOffset, required Uint8List data}); + Uint8List mifareUltralightTransceive({required String handle, required Uint8List bytes}); + void ndefFormatableFormat({required String handle, required PigeonNdefMessage firstMessage}); + void ndefFormatableFormatReadOnly({required String handle, required PigeonNdefMessage firstMessage}); +} + +final class PigeonTag { + const PigeonTag({ + required this.handle, + required this.id, + required this.techList, + required this.ndef, + required this.nfcA, + required this.nfcB, + required this.nfcF, + required this.nfcV, + required this.isoDep, + required this.mifareClassic, + required this.mifareUltralight, + required this.ndefFormatable, + required this.nfcBarcode, + }); + final String handle; + final Uint8List id; + final List techList; + final PigeonNdef? ndef; + final PigeonNfcA? nfcA; + final PigeonNfcB? nfcB; + final PigeonNfcF? nfcF; + final PigeonNfcV? nfcV; + final PigeonIsoDep? isoDep; + final PigeonMifareClassic? mifareClassic; + final PigeonMifareUltralight? mifareUltralight; + final String? ndefFormatable; + final PigeonNfcBarcode? nfcBarcode; +} + +final class PigeonNdef { + const PigeonNdef({ + required this.type, + required this.canMakeReadOnly, + required this.isWritable, + required this.maxSize, + required this.cachedNdefMessage, + }); + final String type; + final bool canMakeReadOnly; + final bool isWritable; + final int maxSize; + final PigeonNdefMessage? cachedNdefMessage; +} + +final class PigeonNfcA { + const PigeonNfcA({ + required this.atqa, + required this.sak, + }); + final Uint8List atqa; + final int sak; +} + +final class PigeonNfcB { + const PigeonNfcB({ + required this.applicationData, + required this.protocolInfo, + }); + final Uint8List applicationData; + final Uint8List protocolInfo; +} + +final class PigeonNfcF { + const PigeonNfcF({ + required this.manufacturer, + required this.systemCode, + }); + final Uint8List manufacturer; + final Uint8List systemCode; +} + +final class PigeonNfcV { + const PigeonNfcV({ + required this.dsfId, + required this.responseFlags, + }); + final int dsfId; + final int responseFlags; +} + +final class PigeonIsoDep { + PigeonIsoDep({ + required this.hiLayerResponse, + required this.historicalBytes, + required this.isExtendedLengthApduSupported, + }); + final Uint8List? hiLayerResponse; + final Uint8List? historicalBytes; + final bool isExtendedLengthApduSupported; +} + +final class PigeonMifareClassic { + const PigeonMifareClassic({ + required this.type, + required this.blockCount, + required this.sectorCount, + required this.size, + }); + final PigeonMifareClassicType type; + final int blockCount; + final int sectorCount; + final int size; +} + +final class PigeonMifareUltralight { + const PigeonMifareUltralight({ + required this.type, + }); + final PigeonMifareUltralightType type; +} + +final class PigeonNfcBarcode { + const PigeonNfcBarcode({ + required this.type, + required this.barcode, + }); + final int type; + final Uint8List barcode; +} + +final class PigeonNdefMessage { + const PigeonNdefMessage({ + required this.records, + }); + final List records; +} + +final class PigeonNdefRecord { + const PigeonNdefRecord({ + required this.tnf, + required this.type, + required this.id, + required this.payload, + }); + final PigeonTypeNameFormat tnf; + final Uint8List type; + final Uint8List id; + final Uint8List payload; +} + +enum PigeonTypeNameFormat { + empty, + wellKnown, + media, + absoluteUri, + external, + unknown, + unchanged, +} + +enum PigeonMifareClassicType { + classic, + plus, + pro, + unknown, +} + +enum PigeonMifareUltralightType { + ultralight, + ultralightC, + unknown, +} diff --git a/pigeon/ios.dart b/pigeon/ios.dart new file mode 100644 index 0000000..48b09ad --- /dev/null +++ b/pigeon/ios.dart @@ -0,0 +1,374 @@ +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon(PigeonOptions( + swiftOut: 'ios/Classes/Pigeon.swift', + dartOut: 'lib/src/nfc_manager_ios/pigeon.g.dart', +)) +@FlutterApi() +abstract final class PigeonFlutterApi { + void tagReaderSessionDidBecomeActive(); + void tagReaderSessionDidDetect(PigeonTag tag); + void tagReaderSessionDidInvalidateWithError(PigeonNfcReaderSessionError error); + void vasReaderSessionDidBecomeActive(); + void vasReaderSessionDidReceive(List responses); + void vasReaderSessionDidInvalidateWithError(PigeonNfcReaderSessionError error); +} + +@HostApi() +abstract final class PigeonHostApi { + bool tagReaderSessionReadingAvailable(); + void tagReaderSessionBegin({required List pollingOptions, required String? alertMessage, required bool invalidateAfterFirstRead}); + void tagReaderSessionInvalidate({required String? alertMessage, required String? errorMessage}); + void tagReaderSessionRestartPolling(); + void tagReaderSessionSetAlertMessage({required String alertMessage}); + bool vasReaderSessionReadingAvailable(); + void vasReaderSessionBegin({required List configurations, required String? alertMessage}); + void vasReaderSessionInvalidate({required String? alertMessage, required String? errorMessage}); + void vasReaderSessionSetAlertMessage({required String alertMessage}); + @async PigeonNDEFQueryStatus ndefQueryNDEFStatus({required String handle}); + @async PigeonNdefMessage? ndefReadNDEF({required String handle}); + @async void ndefWriteNDEF({required String handle, required PigeonNdefMessage message}); + @async void ndefWriteLock({required String handle}); + @async PigeonFeliCaPollingResponse feliCaPolling({required String handle, required Uint8List systemCode, required PigeonFeliCaPollingRequestCode requestCode, required PigeonFeliCaPollingTimeSlot timeSlot}); + @async List feliCaRequestService({required String handle, required List nodeCodeList}); + @async int feliCaRequestResponse({required String handle}); + @async PigeonFeliCaReadWithoutEncryptionResponse feliCaReadWithoutEncryption({required String handle, required List serviceCodeList, required List blockList}); + @async PigeonFeliCaStatusFlag feliCaWriteWithoutEncryption({required String handle, required List serviceCodeList, required List blockList, required List blockData}); + @async List feliCaRequestSystemCode({required String handle}); + @async PigeonFeliCaRequestServiceV2Response feliCaRequestServiceV2({required String handle, required List nodeCodeList}); + @async PigeonFeliCaRequestSpecificationVersionResponse feliCaRequestSpecificationVersion({required String handle}); + @async PigeonFeliCaStatusFlag feliCaResetMode({required String handle}); + @async Uint8List feliCaSendFeliCaCommand({required String handle, required Uint8List commandPacket}); + @async Uint8List miFareSendMiFareCommand({required String handle, required Uint8List commandPacket}); + @async PigeonISO7816ResponseAPDU miFareSendMiFareISO7816Command({required String handle, required PigeonISO7816APDU apdu}); + @async PigeonISO7816ResponseAPDU miFareSendMiFareISO7816CommandRaw({required String handle, required Uint8List data}); + @async PigeonISO7816ResponseAPDU iso7816SendCommand({required String handle, required PigeonISO7816APDU apdu}); + @async PigeonISO7816ResponseAPDU iso7816SendCommandRaw({required String handle, required Uint8List data}); + @async void iso15693StayQuiet({required String handle}); + @async Uint8List iso15693ReadSingleBlock({required String handle, required List requestFlags, required int blockNumber}); + @async void iso15693WriteSingleBlock({required String handle, required List requestFlags, required int blockNumber, required Uint8List dataBlock}); + @async void iso15693LockBlock({required String handle, required List requestFlags, required int blockNumber}); + @async List iso15693ReadMultipleBlocks({required String handle, required List requestFlags, required int blockNumber, required int numberOfBlocks}); + @async void iso15693WriteMultipleBlocks({required String handle, required List requestFlags, required int blockNumber, required int numberOfBlocks, required List dataBlocks}); + @async void iso15693Select({required String handle, required List requestFlags}); + @async void iso15693ResetToReady({required String handle, required List requestFlags}); + @async void iso15693WriteAfi({required String handle, required List requestFlags, required int afi}); + @async void iso15693LockAfi({required String handle, required List requestFlags}); + @async void iso15693WriteDsfId({required String handle, required List requestFlags, required int dsfId}); + @async void iso15693LockDsfId({required String handle, required List requestFlags}); + @async PigeonISO15693SystemInfo iso15693GetSystemInfo({required String handle, required List requestFlags}); + @async List iso15693GetMultipleBlockSecurityStatus({required String handle, required List requestFlags, required int blockNumber, required int numberOfBlocks}); + @async Uint8List iso15693CustomCommand({required String handle, required List requestFlags, required int customCommandCode, required Uint8List customRequestParameters}); +} + +final class PigeonTag { + const PigeonTag({ + required this.handle, + required this.ndef, + required this.feliCa, + required this.iso15693, + required this.iso7816, + required this.miFare, + }); + final String handle; + final PigeonNdef? ndef; + final PigeonFeliCa? feliCa; + final PigeonISO15693? iso15693; + final PigeonISO7816? iso7816; + final PigeonMiFare? miFare; +} + +final class PigeonNdef { + const PigeonNdef({ + required this.status, + required this.capacity, + required this.cachedNdefMessage, + }); + final PigeonNdefStatus status; + final int capacity; + final PigeonNdefMessage? cachedNdefMessage; +} + +final class PigeonFeliCa { + const PigeonFeliCa({ + required this.currentSystemCode, + required this.currentIDm, + }); + final Uint8List currentSystemCode; + final Uint8List currentIDm; +} + +final class PigeonISO15693 { + const PigeonISO15693({ + required this.icManufacturerCode, + required this.icSerialNumber, + required this.identifier, + }); + final int icManufacturerCode; + final Uint8List icSerialNumber; + final Uint8List identifier; +} + +final class PigeonISO7816 { + const PigeonISO7816({ + required this.initialSelectedAID, + required this.identifier, + required this.historicalBytes, + required this.applicationData, + required this.proprietaryApplicationDataCoding, + }); + final String initialSelectedAID; + final Uint8List identifier; + final Uint8List? historicalBytes; + final Uint8List? applicationData; + final bool proprietaryApplicationDataCoding; +} + +final class PigeonMiFare { + const PigeonMiFare({ + required this.mifareFamily, + required this.identifier, + required this.historicalBytes, + }); + final PigeonMiFareFamily mifareFamily; + final Uint8List identifier; + final Uint8List? historicalBytes; +} + +final class PigeonNDEFQueryStatus { + const PigeonNDEFQueryStatus({ + required this.status, + required this.capacity, + }); + final PigeonNdefStatus status; + final int capacity; +} + +final class PigeonNdefMessage { + const PigeonNdefMessage({ + required this.records, + }); + final List records; +} + +final class PigeonNdefPayload { + const PigeonNdefPayload({ + required this.typeNameFormat, + required this.type, + required this.identifier, + required this.payload, + }); + final PigeonTypeNameFormat typeNameFormat; + final Uint8List type; + final Uint8List identifier; + final Uint8List payload; +} + +final class PigeonFeliCaPollingResponse { + const PigeonFeliCaPollingResponse({ + required this.manufacturerParameter, + required this.requestData, + }); + final Uint8List manufacturerParameter; + final Uint8List requestData; +} + +final class PigeonFeliCaReadWithoutEncryptionResponse { + const PigeonFeliCaReadWithoutEncryptionResponse({ + required this.statusFlag1, + required this.statusFlag2, + required this.blockData, + }); + final int statusFlag1; + final int statusFlag2; + final List blockData; +} + +final class PigeonFeliCaRequestServiceV2Response { + const PigeonFeliCaRequestServiceV2Response({ + required this.statusFlag1, + required this.statusFlag2, + required this.encryptionIdentifier, + required this.nodeKeyVersionListAES, + required this.nodeKeyVersionListDES, + }); + final int statusFlag1; + final int statusFlag2; + final int encryptionIdentifier; + final List nodeKeyVersionListAES; + final List nodeKeyVersionListDES; +} + +final class PigeonFeliCaRequestSpecificationVersionResponse { + const PigeonFeliCaRequestSpecificationVersionResponse({ + required this.statusFlag1, + required this.statusFlag2, + required this.basicVersion, + required this.optionVersion, + }); + final int statusFlag1; + final int statusFlag2; + final Uint8List basicVersion; + final Uint8List optionVersion; +} + +final class PigeonFeliCaStatusFlag { + const PigeonFeliCaStatusFlag({ + required this.statusFlag1, + required this.statusFlag2, + }); + final int statusFlag1; + final int statusFlag2; +} + +final class PigeonISO7816APDU { + const PigeonISO7816APDU({ + required this.instructionClass, + required this.instructionCode, + required this.p1Parameter, + required this.p2Parameter, + required this.data, + required this.expectedResponseLength, + }); + final int instructionClass; + final int instructionCode; + final int p1Parameter; + final int p2Parameter; + final Uint8List data; + final int expectedResponseLength; +} + +final class PigeonISO7816ResponseAPDU { + const PigeonISO7816ResponseAPDU({ + required this.payload, + required this.statusWord1, + required this.statusWord2, + }); + final Uint8List payload; + final int statusWord1; + final int statusWord2; +} + +final class PigeonISO15693SystemInfo { + const PigeonISO15693SystemInfo({ + required this.dataStorageFormatIdentifier, + required this.applicationFamilyIdentifier, + required this.blockSize, + required this.totalBlocks, + required this.icReference, + }); + final int dataStorageFormatIdentifier; + final int applicationFamilyIdentifier; + final int blockSize; + final int totalBlocks; + final int icReference; +} + +final class PigeonNfcReaderSessionError { + const PigeonNfcReaderSessionError({ + required this.code, + required this.message, + }); + final PigeonNfcReaderErrorCode code; + final String message; +} + +final class PigeonNfcVasCommandConfiguration { + const PigeonNfcVasCommandConfiguration({ + required this.mode, + required this.passIdentifier, + required this.url, + }); + final PigeonNfcVasCommandConfigurationMode mode; + final String passIdentifier; + final String? url; +} + +final class PigeonNfcVasResponse { + const PigeonNfcVasResponse({ + required this.status, + required this.vasData, + required this.mobileToken, + }); + final PigeonNfcVasResponseErrorCode status; + final Uint8List vasData; + final Uint8List mobileToken; +} + +enum PigeonNdefStatus { + notSupported, + readWrite, + readOnly, +} + +enum PigeonTypeNameFormat { + empty, + wellKnown, + media, + absoluteUri, + external, + unknown, + unchanged, +} + +enum PigeonFeliCaPollingRequestCode { + noRequest, + systemCode, + communicationPerformance, +} + +enum PigeonFeliCaPollingTimeSlot { + max1, + max2, + max4, + max8, + max16, +} + +enum PigeonMiFareFamily { + unknown, + ultralight, + plus, + desfire, +} + +enum PigeonNfcVasCommandConfigurationMode { + normal, + urlOnly, +} + +enum PigeonNfcReaderErrorCode { + readerSessionInvalidationErrorFirstNDEFTagRead, + readerSessionInvalidationErrorSessionTerminatedUnexpectedly, + readerSessionInvalidationErrorSessionTimeout, + readerSessionInvalidationErrorSystemIsBusy, + readerSessionInvalidationErrorUserCanceled, + ndefReaderSessionErrorTagNotWritable, + ndefReaderSessionErrorTagSizeTooSmall, + ndefReaderSessionErrorTagUpdateFailure, + ndefReaderSessionErrorZeroLengthMessage, + readerTransceiveErrorRetryExceeded, + readerTransceiveErrorTagConnectionLost, + readerTransceiveErrorTagNotConnected, + readerTransceiveErrorTagResponseError, + readerTransceiveErrorSessionInvalidated, + readerTransceiveErrorPacketTooLong, + tagCommandConfigurationErrorInvalidParameters, + readerErrorUnsupportedFeature, + readerErrorInvalidParameter, + readerErrorInvalidParameterLength, + readerErrorParameterOutOfBound, + readerErrorRadioDisabled, + readerErrorSecurityViolation, +} + +enum PigeonNfcVasResponseErrorCode { + success, + userIntervention, + dataNotActivated, + dataNotFound, + incorrectData, + unsupportedApplicationVersion, + wrongLCField, + wrongParameters, +} diff --git a/pigeon/pigeon_android.dart b/pigeon/pigeon_android.dart new file mode 100644 index 0000000..84e13d1 --- /dev/null +++ b/pigeon/pigeon_android.dart @@ -0,0 +1,166 @@ +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon(PigeonOptions( + dartOut: 'lib/src/nfc_manager_android/pigeon.g.dart', + kotlinOut: 'android/src/main/kotlin/dev/flutter/plugins/nfcmanager/Pigeon.kt', + kotlinOptions: KotlinOptions(package: 'dev.flutter.plugins.nfcmanager'), +)) + +@FlutterApi() +abstract class PigeonFlutterApi { + void onTagDiscovered(PigeonTag tag); + void onAdapterStateChanged(int state); +} + +@HostApi() +abstract class PigeonHostApi { + bool nfcAdapterIsEnabled(); + bool nfcAdapterIsSecureNfcEnabled(); + bool nfcAdapterIsSecureNfcSupported(); + void nfcAdapterEnableReaderMode(List flags); + void nfcAdapterDisableReaderMode(); + void nfcAdapterEnableForegroundDispatch(); + void nfcAdapterDisableForegroundDispatch(); + PigeonNdefMessage? ndefGetNdefMessage(String handle); + void ndefWriteNdefMessage(String handle, PigeonNdefMessage message); + bool ndefMakeReadOnly(String handle); + int nfcAGetMaxTransceiveLength(String handle); + int nfcAGetTimeout(String handle); + void nfcASetTimeout(String handle, int timeout); + Uint8List nfcATransceive(String handle, Uint8List bytes); + int nfcBGetMaxTransceiveLength(String handle); + Uint8List nfcBTransceive(String handle, Uint8List bytes); + int nfcFGetMaxTransceiveLength(String handle); + int nfcFGetTimeout(String handle); + void nfcFSetTimeout(String handle, int timeout); + Uint8List nfcFTransceive(String handle, Uint8List bytes); + int nfcVGetMaxTransceiveLength(String handle); + Uint8List nfcVTransceive(String handle, Uint8List bytes); + int isoDepGetMaxTransceiveLength(String handle); + int isoDepGetTimeout(String handle); + void isoDepSetTimeout(String handle, int timeout); + Uint8List isoDepTransceive(String handle, Uint8List bytes); + int mifareClassicGetMaxTransceiveLength(String handle); + int mifareClassicGetTimeout(String handle); + void mifareClassicSetTimeout(String handle, int timeout); + int mifareClassicBlockToSector(String handle, int blockIndex); + int mifareClassicGetBlockCountInSector(String handle, int sectorIndex); + int mifareClassicSectorToBlock(String handle, int sectorIndex); + bool mifareClassicAuthenticateSectorWithKeyA(String handle, int sectorIndex, Uint8List key); + bool mifareClassicAuthenticateSectorWithKeyB(String handle, int sectorIndex, Uint8List key); + void mifareClassicIncrement(String handle, int blockIndex, int value); + void mifareClassicDecrement(String handle, int blockIndex, int value); + Uint8List mifareClassicReadBlock(String handle, int blockIndex); + void mifareClassicWriteBlock(String handle, int blockIndex, Uint8List data); + void mifareClassicRestore(String handle, int blockIndex); + void mifareClassicTransfer(String handle, int blockIndex); + Uint8List mifareClassicTransceive(String handle, Uint8List bytes); + int mifareUltralightGetMaxTransceiveLength(String handle); + int mifareUltralightGetTimeout(String handle); + void mifareUltralightSetTimeout(String handle, int timeout); + Uint8List mifareUltralightReadPages(String handle, int pageOffset); + void mifareUltralightWritePage(String handle, int pageOffset, Uint8List data); + Uint8List mifareUltralightTransceive(String handle, Uint8List bytes); + void ndefFormatableFormat(String handle, PigeonNdefMessage firstMessage); + void ndefFormatableFormatReadOnly(String handle, PigeonNdefMessage firstMessage); +} + +class PigeonTag { + String? handle; + Uint8List? id; + List? techList; + PigeonNdef? ndef; + PigeonNfcA? nfcA; + PigeonNfcB? nfcB; + PigeonNfcF? nfcF; + PigeonNfcV? nfcV; + PigeonIsoDep? isoDep; + PigeonMifareClassic? mifareClassic; + PigeonMifareUltralight? mifareUltralight; + String? ndefFormatable; + PigeonNfcBarcode? nfcBarcode; +} + +class PigeonNdef { + String? type; + bool? canMakeReadOnly; + bool? isWritable; + int? maxSize; + PigeonNdefMessage? cachedNdefMessage; +} + +class PigeonNfcA { + Uint8List? atqa; + int? sak; +} + +class PigeonNfcB { + Uint8List? applicationData; + Uint8List? protocolInfo; +} + +class PigeonNfcF { + Uint8List? manufacturer; + Uint8List? systemCode; +} + +class PigeonNfcV { + int? dsfId; + int? responseFlags; +} + +class PigeonIsoDep { + Uint8List? hiLayerResponse; + Uint8List? historicalBytes; + bool? isExtendedLengthApduSupported; +} + +class PigeonMifareClassic { + PigeonMifareClassicType? type; + int? blockCount; + int? sectorCount; + int? size; +} + +class PigeonMifareUltralight { + PigeonMifareUltralightType? type; +} + +class PigeonNfcBarcode { + int? type; + Uint8List? barcode; +} + +class PigeonNdefMessage { + List? records; +} + +class PigeonNdefRecord { + PigeonTypeNameFormat? tnf; + Uint8List? type; + Uint8List? id; + Uint8List? payload; +} + +enum PigeonTypeNameFormat { + empty, + wellKnown, + mimeMedia, + absoluteUri, + externalType, + unknown, + unchanged, +} + +enum PigeonMifareClassicType { + classic, + plus, + pro, + unknown, +} + +enum PigeonMifareUltralightType { + ultralight, + ultralightC, + unknown, +} diff --git a/pigeon/pigeon_ios.dart b/pigeon/pigeon_ios.dart new file mode 100644 index 0000000..fd65805 --- /dev/null +++ b/pigeon/pigeon_ios.dart @@ -0,0 +1,266 @@ +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon(PigeonOptions( + swiftOut: 'ios/Classes/Pigeon.swift', + dartOut: 'lib/src/nfc_manager_ios/pigeon.g.dart', +)) +@FlutterApi() +abstract class PigeonFlutterApi { + void tagReaderSessionDidBecomeActive(); + void tagReaderSessionDidDetect(PigeonTag tag); + void tagReaderSessionDidInvalidateWithError(PigeonNfcReaderSessionError error); + void vasReaderSessionDidBecomeActive(); + void vasReaderSessionDidReceive(List responses); + void vasReaderSessionDidInvalidateWithError(PigeonNfcReaderSessionError error); +} + +@HostApi() +abstract class PigeonHostApi { + bool tagReaderSessionReadingAvailable(); + void tagReaderSessionBegin(List pollingOptions, String? alertMessage, bool invalidateAfterFirstRead); + void tagReaderSessionInvalidate(String? alertMessage, String? errorMessage); + void tagReaderSessionRestartPolling(); + void tagReaderSessionSetAlertMessage(String alertMessage); + void vasReaderSessionBegin(List configurations, String? alertMessage); + void vasReaderSessionInvalidate(String? alertMessage, String? errorMessage); + void vasReaderSessionSetAlertMessage(String alertMessage); + @async PigeonNDEFQueryStatus ndefQueryNDEFStatus(String handle); + @async PigeonNdefMessage? ndefReadNDEF(String handle); + @async void ndefWriteNDEF(String handle, PigeonNdefMessage message); + @async void ndefWriteLock(String handle); + @async PigeonFeliCaPollingResponse feliCaPolling(String handle, Uint8List systemCode, PigeonFeliCaPollingRequestCode requestCode, PigeonFeliCaPollingTimeSlot timeSlot); + @async List feliCaRequestService(String handle, List nodeCodeList); + @async int feliCaRequestResponse(String handle); + @async PigeonFeliCaReadWithoutEncryptionResponse feliCaReadWithoutEncryption(String handle, List serviceCodeList, List blockList); + @async PigeonFeliCaStatusFlag feliCaWriteWithoutEncryption(String handle, List serviceCodeList, List blockList, List blockData); + @async List feliCaRequestSystemCode(String handle); + @async PigeonFeliCaRequestServiceV2Response feliCaRequestServiceV2(String handle, List nodeCodeList); + @async PigeonFeliCaRequestSpecificationVersionResponse feliCaRequestSpecificationVersion(String handle); + @async PigeonFeliCaStatusFlag feliCaResetMode(String handle); + @async Uint8List feliCaSendFeliCaCommand(String handle, Uint8List commandPacket); + @async Uint8List miFareSendMiFareCommand(String handle, Uint8List commandPacket); + @async PigeonISO7816ResponseAPDU miFareSendMiFareISO7816Command(String handle, PigeonISO7816APDU apdu); + @async PigeonISO7816ResponseAPDU miFareSendMiFareISO7816CommandRaw(String handle, Uint8List data); + @async PigeonISO7816ResponseAPDU iso7816SendCommand(String handle, PigeonISO7816APDU apdu); + @async PigeonISO7816ResponseAPDU iso7816SendCommandRaw(String handle, Uint8List data); + @async void iso15693StayQuiet(String handle); + @async Uint8List iso15693ReadSingleBlock(String handle, List requestFlags, int blockNumber); + @async void iso15693WriteSingleBlock(String handle, List requestFlags, int blockNumber, Uint8List dataBlock); + @async void iso15693LockBlock(String handle, List requestFlags, int blockNumber); + @async List iso15693ReadMultipleBlocks(String handle, List requestFlags, int blockNumber, int numberOfBlocks); + @async void iso15693WriteMultipleBlocks(String handle, List requestFlags, int blockNumber, int numberOfBlocks, List dataBlocks); + @async void iso15693Select(String handle, List requestFlags); + @async void iso15693ResetToReady(String handle, List requestFlags); + @async void iso15693WriteAfi(String handle, List requestFlags, int afi); + @async void iso15693LockAfi(String handle, List requestFlags); + @async void iso15693WriteDsfId(String handle, List requestFlags, int dsfId); + @async void iso15693LockDsfId(String handle, List requestFlags); + @async PigeonISO15693SystemInfo iso15693GetSystemInfo(String handle, List requestFlags); + @async List iso15693GetMultipleBlockSecurityStatus(String handle, List requestFlags, int blockNumber, int numberOfBlocks); + @async Uint8List iso15693CustomCommand(String handle, List requestFlags, int customCommandCode, Uint8List customRequestParameters); +} + +class PigeonTag { + String? handle; + PigeonNdef? ndef; + PigeonFeliCa? feliCa; + PigeonISO15693? iso15693; + PigeonISO7816? iso7816; + PigeonMiFare? miFare; +} + +class PigeonNdef { + PigeonNdefStatus? status; + int? capacity; + PigeonNdefMessage? cachedNdefMessage; +} + +class PigeonFeliCa { + Uint8List? currentSystemCode; + Uint8List? currentIDm; +} + +class PigeonISO15693 { + int? icManufacturerCode; + Uint8List? icSerialNumber; + Uint8List? identifier; +} + +class PigeonISO7816 { + String? initialSelectedAID; + Uint8List? identifier; + Uint8List? historicalBytes; + Uint8List? applicationData; + bool? proprietaryApplicationDataCoding; +} + +class PigeonMiFare { + PigeonMiFareFamily? mifareFamily; + Uint8List? identifier; + Uint8List? historicalBytes; +} + +class PigeonNDEFQueryStatus { + PigeonNdefStatus? status; + int? capacity; +} + +class PigeonNdefMessage { + List? records; +} + +class PigeonNdefPayload { + PigeonTypeNameFormat? typeNameFormat; + Uint8List? type; + Uint8List? identifier; + Uint8List? payload; +} + +class PigeonFeliCaPollingResponse { + Uint8List? manufacturerParameter; + Uint8List? requestData; +} + +class PigeonFeliCaReadWithoutEncryptionResponse { + int? statusFlag1; + int? statusFlag2; + List? blockData; +} + +class PigeonFeliCaRequestServiceV2Response { + int? statusFlag1; + int? statusFlag2; + int? encryptionIdentifier; + List? nodeKeyVersionListAES; + List? nodeKeyVersionListDES; +} + +class PigeonFeliCaRequestSpecificationVersionResponse { + int? statusFlag1; + int? statusFlag2; + Uint8List? basicVersion; + Uint8List? optionVersion; +} + +class PigeonFeliCaStatusFlag { + int? statusFlag1; + int? statusFlag2; +} + +class PigeonISO7816APDU { + int? instructionClass; + int? instructionCode; + int? p1Parameter; + int? p2Parameter; + Uint8List? data; + int? expectedResponseLength; +} + +class PigeonISO7816ResponseAPDU { + Uint8List? payload; + int? statusWord1; + int? statusWord2; +} + +class PigeonISO15693SystemInfo { + int? dataStorageFormatIdentifier; + int? applicationFamilyIdentifier; + int? blockSize; + int? totalBlocks; + int? icReference; +} + +class PigeonNfcReaderSessionError { + PigeonNfcReaderErrorCode? code; + String? message; +} + +class PigeonNfcVasCommandConfiguration { + PigeonNfcVasCommandConfigurationMode? mode; + String? passIdentifier; + String? url; +} + +class PigeonNfcVasResponse { + PigeonNfcVasResponseErrorCode? status; + Uint8List? vasData; + Uint8List? mobileToken; +} + +enum PigeonNdefStatus { + notSupported, + readWrite, + readOnly, +} + +enum PigeonTypeNameFormat { + empty, + nfcWellKnown, + media, + absoluteUri, + nfcExternal, + unknown, + unchanged, +} + +enum PigeonFeliCaPollingRequestCode { + noRequest, + systemCode, + communicationPerformance, +} + +enum PigeonFeliCaPollingTimeSlot { + max1, + max2, + max4, + max8, + max16, +} + +enum PigeonMiFareFamily { + unknown, + ultralight, + plus, + desfire, +} + +enum PigeonNfcVasCommandConfigurationMode { + normal, + urlOnly, +} + +enum PigeonNfcReaderErrorCode { + readerSessionInvalidationErrorFirstNDEFTagRead, + readerSessionInvalidationErrorSessionTerminatedUnexpectedly, + readerSessionInvalidationErrorSessionTimeout, + readerSessionInvalidationErrorSystemIsBusy, + readerSessionInvalidationErrorUserCanceled, + ndefReaderSessionErrorTagNotWritable, + ndefReaderSessionErrorTagSizeTooSmall, + ndefReaderSessionErrorTagUpdateFailure, + ndefReaderSessionErrorZeroLengthMessage, + readerTransceiveErrorRetryExceeded, + readerTransceiveErrorTagConnectionLost, + readerTransceiveErrorTagNotConnected, + readerTransceiveErrorTagResponseError, + readerTransceiveErrorSessionInvalidated, + readerTransceiveErrorPacketTooLong, + tagCommandConfigurationErrorInvalidParameters, + readerErrorUnsupportedFeature, + readerErrorInvalidParameter, + readerErrorInvalidParameterLength, + readerErrorParameterOutOfBound, + readerErrorRadioDisabled, + readerErrorSecurityViolation, +} + +enum PigeonNfcVasResponseErrorCode { + success, + userIntervention, + dataNotActivated, + dataNotFound, + incorrectData, + unsupportedApplicationVersion, + wrongLCField, + wrongParameters, +} diff --git a/pubspec.yaml b/pubspec.yaml index e3654f2..c4f7370 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,25 +1,29 @@ name: nfc_manager -description: Flutter plugin for accessing the NFC features on Android and iOS. -version: 3.2.0 -homepage: https://github.com/okadan/flutter-nfc-manager +description: A Flutter plugin for accessing the NFC features on Android and iOS. +version: 4.0.0-dev +repository: https://github.com/okadan/flutter-nfc-manager +publish_to: 'none' # TODO: remove this line environment: - sdk: '>=2.18.1 <3.0.0' - flutter: ">=2.5.0" + sdk: '>=3.2.0 <4.0.0' + flutter: '>=3.3.0' dependencies: flutter: sdk: flutter + ndef_record: + git: https://github.com/okadan/dart-ndef-record dev_dependencies: flutter_test: sdk: flutter + pigeon: flutter: plugin: platforms: android: - package: io.flutter.plugins.nfcmanager + package: dev.flutter.plugins.nfcmanager pluginClass: NfcManagerPlugin ios: pluginClass: NfcManagerPlugin