Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Nejc Skerjanc committed Dec 31, 2024
1 parent d47c05c commit 19906e4
Show file tree
Hide file tree
Showing 45 changed files with 1,257 additions and 849 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/example-app.yml

This file was deleted.

61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,64 @@
## 3.3.3

* Fix build script of Android plugin and remove AGP version requirement (#110)

## 3.4.0

* Add support for reading / write MIFARE Classic / Ultralight tags on Android (merged #82, partially fixes #82)
* Add support for reading / write ISO 15693 tags on iOS (merged #117, partially fixes #68)
* Fix compiling issues (#123)
* Other minor fixes (#114, #115)

## 3.4.1

**This version is *deprecated* due to a bug in Mifare tag handling. Please upgrade to 3.4.2.**

* Fix & split examples to example/ dir
* Publish examples to pub.dev
* Support transceiving of raw ISO15693 commands on iOS

## 3.4.2

* Fix polling error on Mifare tags (#126, #128, #129, #133)

## 3.5.0

* Some FeliCa improvements by @shiwano:
* Fix missing `id` field in FeliCa card reading on iOS (#140)
* Set the IDm to the `id` and the PMm to the `manufacturer` on iOS (#140)
* Add `iosRestartPolling` method by @rostopira (#151)
* Fix type assertion in `authenticateSector` (fix #148)
* Refine exception handling in Android plugin (fix #91 and #149)
* Bump multiple dependencies:
* Android plugin / example app: Java 17, AGP 7.4.2, Kotlin 1.9.23, minSdkVersion 26 (fix #127, #144, #145)
* `js` library: 0.7.1

## 3.5.1

* Fix multiple issues related to `authenticateSector` (#159):
* Fix type checking assertions of arguments
* Add missing call to `connect` in Android plugin
* Add instruction on resolving `js` dependency conflict in README

## 3.5.2

* Some MiFare Classic fixes by @knthm:
* allow authentication of sector 0 (#157)
* fix data type check in `writeBlock` (#161)

## 3.6.0-rc.6

This is a release candidate for 3.6.0. Please test it and report any issues.

* Requires Dart 3.6+ and Flutter 3.24+
* Remove annoying dependency on `js` library, replace with `dart:js_interop`
* Remove dependency on `dart:io`
* Contributions on Android plugin from @knthm:
* Dedicated handler thread for IO operations (#167)
* More elegant exception handling (#169)
* Bump tool versions & dependencies of Android plugin and example app:
* Related issues / PRs: #179 #184, #186, #187
* Now requiring Java 17, Gradle 8.9, MinSDKVer 26, AGP 8.7, Kotlin 2.1.0
* Add Swift package manager support for iOS plugin, bump dependencies
* Fix WebUSB interop on Web, add onDisconnect callback
* Add support for foreground polling on Android (#16, #179)
81 changes: 22 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,37 @@ This plugin's functionalities include:
* ISO 14443 Type A & Type B (NFC-A / NFC-B / MIFARE Classic / MIFARE Plus / MIFARE Ultralight / MIFARE DESFire)
* ISO 18092 (NFC-F / FeliCa)
* ISO 15963 (NFC-V)
* transceive commands with tags / cards complying with:
* R/W block / page / sector level data of tags complying with:
* MIFARE Classic / Ultralight (Android only)
* ISO 15693 (iOS only)
* transceive raw commands with tags / cards complying with:
* ISO 7816 Smart Cards (layer 4, in APDUs)
* other device-supported technologies (layer 3, in raw commands, see documentation for platform-specific supportability)

Note that due to API limitations not all operations are supported on both platforms.
Note that due to API limitations, not all operations are supported on all platforms.
**You are welcome to submit PRs to add support for any standard-specific operations.**

This library uses [ndef](https://pub.dev/packages/ndef) for NDEF record encoding & decoding.

## Setup

Thank [nfc_manager](https://pub.dev/packages/nfc_manager) plugin for these instructions.

### Android

We have the following minimum version requirements for Android plugin:

* Java 17
* Gradle 8.9
* Android SDK 26 (you must set corresponding `jvmTarget` in you app's `build.gradle`)
* Android Gradle Plugin 8.7

To use this plugin on Android, you also need to:

* Add [android.permission.NFC](https://developer.android.com/reference/android/Manifest.permission.html#NFC) to your `AndroidManifest.xml`.

### iOS

This plugin now supports Swift package manager, and requires iOS 13+.

* Add [Near Field Communication Tag Reader Session Formats Entitlements](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_nfc_readersession_formats) to your entitlements.
* 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. WARNING: for iOS 14.5 and earlier versions, you **MUST** add them before invoking `poll` with `readIso18092` or `readIso15693` enabled, or your NFC **WILL BE TOTALLY UNAVAILABLE BEFORE REBOOT** due to a [CoreNFC bug](https://github.com/nfcim/flutter_nfc_kit/issues/23).
Expand All @@ -43,64 +56,14 @@ Make sure you understand the statement above and the protocol before using this

## Usage

Simple example:

```dart
import 'package:flutter_nfc_kit/flutter_nfc_kit.dart';
import 'package:ndef/ndef.dart' as ndef;
var availability = await FlutterNfcKit.nfcAvailability;
if (availability != NFCAvailability.available) {
// oh-no
}
// timeout only works on Android, while the latter two messages are only for iOS
var tag = await FlutterNfcKit.poll(timeout: Duration(seconds: 10),
iosMultipleTagMessage: "Multiple tags found!", iosAlertMessage: "Scan your tag");
print(jsonEncode(tag));
if (tag.type == NFCTagType.iso7816) {
var result = await FlutterNfcKit.transceive("00B0950000", Duration(seconds: 5)); // timeout is still Android-only, persist until next change
print(result);
}
// iOS only: set alert message on-the-fly
// this will persist until finish()
await FlutterNfcKit.setIosAlertMessage("hi there!");
// read NDEF records if available
if (tag.ndefAvailable){
/// decoded NDEF records (see [ndef.NDEFRecord] for details)
/// `UriRecord: id=(empty) typeNameFormat=TypeNameFormat.nfcWellKnown type=U uri=https://github.com/nfcim/ndef`
for (var record in await FlutterNfcKit.readNDEFRecords(cached: false)) {
print(record.toString());
}
/// raw NDEF records (data in hex string)
/// `{identifier: "", payload: "00010203", type: "0001", typeNameFormat: "nfcWellKnown"}`
for (var record in await FlutterNfcKit.readNDEFRawRecords(cached: false)) {
print(jsonEncode(record).toString());
}
}
// write NDEF records if applicable
if (tag.ndefWritable) {
// decoded NDEF records
await FlutterNfcKit.writeNDEFRecords([new ndef.UriRecord.fromUriString("https://github.com/nfcim/flutter_nfc_kit")]);
// raw NDEF records
await FlutterNfcKit.writeNDEFRawRecords([new NDEFRawRecord("00", "0001", "0002", "0003", ndef.TypeNameFormat.unknown)]);
}
// Call finish() only once
await FlutterNfcKit.finish();
// iOS only: show alert/error message on finish
await FlutterNfcKit.finish(iosAlertMessage: "Success");
// or
await FlutterNfcKit.finish(iosErrorMessage: "Failed");
```

A more complicated example can be seen in `example` dir.
We provide [simple code example](example/example.md) and a [example application](example/lib).

Refer to the [documentation](https://pub.dev/documentation/flutter_nfc_kit/) for more information.

### Error codes

We use error codes with similar meaning as HTTP status code. Brief explanation and error cause in string (if available) will also be returned when an error occurs.

### Operation Mode

We provide two operation modes: polling (default) and event streaming. Both can give the same `NFCTag` object. Please see [example](example/example.md) for more details.
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lints/recommended.yaml

linter:
rules:
constant_identifier_names: false
19 changes: 11 additions & 8 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ group 'im.nfc.flutter_nfc_kit'

android {

namespace 'im.nfc.flutter_nfc_kit'
if (project.android.hasProperty("namespace")) {
namespace 'im.nfc.flutter_nfc_kit'
}

compileSdkVersion 33
compileSdk 35

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
minSdkVersion 19
minSdkVersion 26
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand All @@ -37,7 +43,4 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$KotlinVersion"
implementation 'androidx.core:core-ktx:1.10.1'
}
5 changes: 2 additions & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
AGPVersion=7.0.4
KotlinVersion=1.9.10
AGPVersion=8.7.3
KotlinVersion=2.1.0
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Sep 08 22:01:14 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 19906e4

Please sign in to comment.