nfc_manager 4.0.0-dev
nfc_manager: ^4.0.0-dev copied to clipboard
A Flutter plugin for accessing the NFC features on Android and iOS.
nfc_manager #
A Flutter plugin for accessing the NFC features on Android and iOS.
Requirements #
Android SDK Version >= 19 or iOS >= 12.0. (TODO: iOS 13.0)
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.plist
. (Optional) -
Add com.apple.developer.nfc.readersession.felica.systemcodes to your
Info.plist
. (Optional but required if you specify theNfcPollingOptions.iso18092
to thepollingOptions
)
Handling the NFC Session #
bool isAvailable = await NfcManager.instance.isAvailable();
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.
await NfcManager.instance.stopSession();
},
);
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:
Android Only
NdefAndroid
NfcAAndroid
NfcBAndroid
NfcFAndroid
NfcVAndroid
IsoDepAndroid
MifareClassicAndroid
MifareUltralightAndroid
NdefFormatableAndroid
NfcBarcodeAndroid
iOS Only
NdefIOS
MiFareIOS
FeliCaIOS
Iso15693IOS
Iso7618IOS
Abstraction between Android and iOS (sub packages)
Ndef
(package: nfc_manager_ndef)FeliCa
(package: 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
:
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';
Ndef? ndef = Ndef.from(tag);
if (ndef == null) {
print("The tag is not compatible with an NDEF.");
return;
}
// Do something with an Ndef instance.
See the example directory or Real World App for more informations.