nfc_manager
4.2.1A Flutter plugin providing access to NFC features on Android and iOS.
Readme
nfc_manager
A Flutter plugin providing access to NFC features on Android and iOS.
Setup
Android
- Add android.permission.NFC to your
AndroidManifest.xml.
iOS
- Add Near Field Communication Tag Reader Session Formats Entitlements to your entitlements.
- Add NFCReaderUsageDescription to your
Info.plist. - Add com.apple.developer.nfc.readersession.iso7816.select-identifiers to your
Info.plistas needed. - Add com.apple.developer.nfc.readersession.felica.systemcodes to your
Info.plistif you specifyNfcPollingOption.iso18092instartSession, otherwise an error will occur.
Usage
Handling the Session
import 'package:nfc_manager/nfc_manager.dart';
// Check the availability of NFC on the current device.
NfcAvailability availability = await NfcManager.instance.checkAvailability();
if (availability != NfcAvailability.enabled) {
print('NFC may not be supported or may be temporarily disabled.');
return;
}
// Start the session.
NfcManager.instance.startSession(
pollingOptions: {NfcPollingOption.iso14443}, // You can also specify iso18092 and iso15693.
onDiscovered: (NfcTag tag) async {
// Do something with an NfcTag instance...
print(tag);
// Stop the session when no longer needed.
await NfcManager.instance.stopSession();
},
);
Working with NfcTag
An NfcTag instance is typically not used directly. Instead, convert it to a platform-specific tag class by calling that class's static method from.
import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';
final Ndef ndef = Ndef.from(tag);
if (ndef == null) {
print('This tag is not compatible with NDEF.');
return;
}
// Do something with an Ndef instance...
print(ndef);
The following platform-specific tag classes are available:
Android only
NfcAAndroidNfcBAndroidNfcFAndroidNfcVAndroidIsoDepAndroidMifareClassicAndroidMifareUltralightAndroidNfcBarcodeAndroidNdefAndroidNdefFormatableAndroid
iOS only
FeliCaIosMiFareIosIso15693IosIso7816IosNdefIos
Cross-platform abstractions (separate packages)
Ndef(nfc_manager_ndef)FeliCa(nfc_manager_felica)- and more...
Changelog
4.2.1
- Fixes crash when re-opening the app from background.
4.2.0
- Add Swift Package Manager support.
- Bump dependencies.
4.1.1
- Avoid iOS SDK version constraints caused by the addition of
NFCReaderError.Code.
4.1.0
- Deprecated
NfcManager#isAvailable. UseNfcManager#checkAvailabilityinstead. - Fix iOS background issue.
- Add more
NFCReaderError.Codefor iOS. - Bump versions.
- Update doc.
4.0.2
- Update README.
4.0.1
- Update package page.
4.0.0
Has many breaking changes.
- Rename the following:
NfcAtoNfcAAndroidNfcBtoNfcBAndroidNfcFtoNfcFAndroidNfcVtoNfcVAndroidIsoDeptoIsoDepAndroidMifareClassictoMifareClassicAndroidMifareUltralighttoMifareUltralightAndroidNdefFormatabletoNdefFormatableAndroidMiFaretoMiFareIosFeliCatoFeliCaIosIso15693toIso15693IosIso7816toIso7816Ios- Options for
startSession:onErrortoonErrorIosinvalidateAfterFirstReadtoinvalidateAfterFirstReadIosalertMessagetoalertMessageIos
- Options for
stopSession:alertMessagetoalertMessageIoserrorMessagetoerrorMessageIos
- Remove the following:
Ndef(Instead use thenfc_manager_ndefpackage orNdefAndroid/NdefIos)timeout(Instead use theasync getTimeout()method)maxTransceiveLength(Instead use theasync getMaxTransceiveLength()method)NfcError(Instead use theNfcReaderSessionErrorIos)NfcErrorType(Instead use theNfcReaderErrorCodeIos)
- Add the following:
ndef_record.dartlibrary that provides access tondef_recordpackage.nfc_manager_android.dartlibrary that provides access to Android API.nfc_manager_ios.dartlibrary that provides access to iOS API.async setTimeout()method.noPlatformSoundsAndroidoption tostartSessionmethod.
- Upgrade Flutter.
- Update README.
3.5.1
- Make compatible for Kotlin 2.1.0
3.5.0
- Upgrade Flutter.
- Fix analyze issues.
3.4.0
- Fix iOS background isolate issue.
- Add namespace to Gradle for Android.
- Rebuild projects on Flutter stable channel.
3.3.0
- Added
invalidateAfterFirstReadargument tostartSession. This enablesrestartPollingon iOS.
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#hiLayerResponseIsoDep#historicalBytesIso7816#historicalBytesIso7816#applicationDataMiFare#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#readWithoutEncryptionandFeliCa#requestServiceV2.
2.0.2
- Fix a bug in calling
FeliCa.sendFeliCaCommandmethod.
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
startNdefSessionandNdefDiscoveredCallback. - Rename
startTagSessiontostartSession. - Rename
TagPollingOptiontoNfcPollingOption. - Rename
NfcSessionErrortoNfcError. - Rename
NfcSessionErrorTypetoNfcErrorType. - Rename
TagDiscoveredCallbacktoNfcTagCallback. - Rename
NfcSessionErrorCallbacktoNfcErrorCallback. - Rename
ISO15693toIso15693. - Rename
ISO7816toIso7816. - Rename
fromTagtofrom. (e.g.MiFare.fromTag(tag)->MiFare.from(tag)) - Add
NdefTypeNameFormatenum. - Add
NdefFormatable,MifareClassicandMifareUltralightclasses. - Add
Ndef#readmethod. - Add command-implementations for
FeliCaandIso15693. - 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
NfcSessionTypeenum. - 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#cachedNdeftoNfcNdef#cachedMessage. - Add
NfcSessionTypeenum. - Add
NfcTagPollingOptionenum.
0.3.0
- Add
NdefRecord#createMimeRecord. - Add optional parameters
alertMessageIOSanderrorMessageIOSdisplayed in iOS system UI. - Fix error on deserializing null message on dart side.
0.2.0
- Split
startSessionintostartNdefSessionandstartTagSession. - 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.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add nfc_managerpubspec.yaml
name: nfc_manager
description: A Flutter plugin providing access to NFC features on Android and iOS.
repository: https://github.com/okadan/flutter-nfc-manager
version: 4.2.1
environment:
sdk: ^3.11.4
flutter: '>=3.3.0'
dependencies:
flutter:
sdk: flutter
meta: ^1.17.0
ndef_record: ^1.4.2
dev_dependencies:
flutter_lints: ^6.0.0
pigeon: ^26.3.3
flutter:
plugin:
platforms:
android:
package: dev.flutter.plugins.nfcmanager
pluginClass: NfcManagerPlugin
ios:
pluginClass: NfcManagerPlugin
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | On demand | Download | eccc758f…dfa1ea |
| 0.1.0 | On demand | Download | e2db25c8…fc1f40 |
| 0.1.0+1 | On demand | Download | 06dc7d54…bba8ad |
| 0.1.0+2 | On demand | Download | 542e6e18…d4774a |
| 0.1.1 | On demand | Download | df3bcc98…6e3ec2 |
| 0.2.0 | On demand | Download | 13a27627…0de2d8 |
| 0.3.0 | On demand | Download | 30b25d0c…1050ef |
| 0.4.0 | On demand | Download | 78ee9d3a…b00751 |
| 0.4.0+1 | On demand | Download | 1a692e26…dc2d45 |
| 0.4.0+2 | On demand | Download | 5ba9255d…d63307 |
| 0.5.0 | On demand | Download | f9bdbaa2…914297 |
| 0.5.1 | On demand | Download | cdc01186…ed721f |
| 1.0.0-dev | On demand | Download | bf79b0e3…e50e68 |
| 1.0.0-dev.1 | On demand | Download | 5718e0c3…882d36 |
| 1.0.0-dev.2 | On demand | Download | 6aef44d1…e9eebb |
| 1.0.0-dev.3 | On demand | Download | 592a0a74…fb0d58 |
| 1.0.0-dev.4 | On demand | Download | a4ee5a86…6da4a9 |
| 1.0.0-dev.5 | On demand | Download | 4267ef5d…9a2e55 |
| 1.0.0-dev.6 | On demand | Download | 38b4fe27…ef3864 |
| 1.0.0-dev.7 | On demand | Download | 5fa70a38…aff9e5 |
| 1.0.0 | On demand | Download | 5a64dbbb…a7753b |
| 1.0.1 | On demand | Download | 97bcad18…e7e63b |
| 1.1.0 | On demand | Download | f4d5e1d0…17d400 |
| 1.1.0+1 | On demand | Download | 7639a692…890af8 |
| 1.2.0 | On demand | Download | daf669ba…9e87eb |
| 1.3.0-dev | On demand | Download | 6d89b714…7198e3 |
| 1.3.0-dev+1 | On demand | Download | b784ba26…e4bb57 |
| 1.3.0 | On demand | Download | fe31802e…3751eb |
| 1.3.1 | On demand | Download | bfdc66d2…8dc54a |
| 1.3.2 | On demand | Download | 5901fbff…276e17 |
| 1.3.2+1 | On demand | Download | d204a894…ab122b |
| 1.3.2+2 | On demand | Download | 5e9d8fb8…294a1a |
| 1.3.2+3 | On demand | Download | 76d787f3…6a2282 |
| 1.3.2+4 | On demand | Download | 8a5ff556…cbd6c5 |
| 1.4.0-dev | On demand | Download | e3c3772f…944fe1 |
| 1.4.0-dev+1 | On demand | Download | d5465157…9a477c |
| 1.4.0-dev+2 | On demand | Download | 23fa886f…33181d |
| 1.4.0-dev+3 | On demand | Download | ce593986…534027 |
| 1.4.0-dev+4 | On demand | Download | 1ffc5002…a9f433 |
| 2.0.0-dev | On demand | Download | 5ca3b483…f6e96f |
| 2.0.0 | On demand | Download | 9fc4899b…64628f |
| 2.0.0+1 | On demand | Download | 788612d5…fd1fb4 |
| 2.0.0+2 | On demand | Download | 54bc39d5…84a84f |
| 2.0.1 | On demand | Download | 4d632ced…aa04af |
| 2.0.1+1 | On demand | Download | 8fe2eabf…3ec89c |
| 2.0.2 | On demand | Download | 9a3ebae0…19bcc0 |
| 2.0.3 | On demand | Download | e25b9585…35512f |
| 3.0.0 | On demand | Download | f06b3cd8…3d08e7 |
| 3.0.0+1 | On demand | Download | 92976b42…b3c7a6 |
| 3.0.0+2 | On demand | Download | b6d62464…529510 |
| 3.1.0 | On demand | Download | 1571c62a…4417ac |
| 3.1.1 | On demand | Download | e967e5b0…25baf0 |
| 3.2.0 | On demand | Download | cff1e59e…3b0f4a |
| 3.3.0 | On demand | Download | d6a4cc6a…970baf |
| 3.4.0 | On demand | Download | 25b3ed2a…7f08c5 |
| 3.5.0 | On demand | Download | f5be75e9…ff8c59 |
| 3.5.1 | On demand | Download | 071faa6e…03c326 |
| 4.0.0-dev | On demand | Download | e4290103…262398 |
| 4.0.0 | On demand | Download | 61f8d7ec…d5ac38 |
| 4.0.1 | On demand | Download | 536c1352…b2fb2d |
| 4.0.2 | On demand | Download | 164cc022…57f676 |
| 4.1.0 | On demand | Download | 4977eec6…3541aa |
| 4.1.1 | On demand | Download | 24c78b0e…866879 |
| 4.2.0 | On demand | Download | a88e174e…3ba6fa |
| 4.2.1 | Cached · Upstream SHA-256 matched | Download | 1b8d3788…151fe6 |
Dependencies
flutter {
"sdk": "flutter"
}
meta "^1.17.0"
ndef_record "^1.4.2"