nfc_manager 0.4.0+2
nfc_manager: ^0.4.0+2 copied to clipboard
A Flutter plugin to use NFC. Supported on both Android and iOS.
nfc_manager #
A Flutter plugin to use NFC. Supported on both Android and iOS.
Note #
This plugin is still under development.
So please use with caution as there may be potential issues and breaking changes.
Feedback is welcome.
Setup #
Android Setup #
- Add android.permission.NFC to your
AndroidMenifest.xml
.
iOS Setup #
-
Add Near Field Communication Tag Reader Session Formats Entitlements to your entitlements.
-
Add NFCReaderUsageDescription to your
Info.plist
. -
If you use
NfcManager#startTagSession
withNfcTagPollingOption.iso18092
, you must add com.apple.developer.nfc.readersession.felica.systemcodes to yourInfo.plist
.
Usage #
Reading NDEF #
NfcManager.instance.startNdefSession(
alertMessageIOS: '[Any message displayed on the iOS system UI]',
onNdefDiscovered: (NfcNdef ndef) {
print(ndef);
},
);
Writing NDEF #
NfcManager.instance.startNdefSession(
alertMessageIOS: '...',
onNdefDiscovered: (NfcNdef ndef) async {
if (!ndef.isWritable) {
print('Tag is not ndef writable.');
return;
}
final NdefMessage message = NdefMessage([
NdefRecord.createTextRecord('Hello World'),
NdefRecord.createUriRecord(Uri.parse('https://flutter.dev')),
NdefRecord.createMimeRecord('plain/text', Uint8List.fromList('Hello World'.codeUnits)),
NdefRecord.createExternalRecord([domain string], [type string], [data uint8list]),
]);
try {
await ndef.writeNdef(message);
} catch (e) {
// handle error
}
},
);
Reading Tag #
NfcManager.instance.startTagSession(
alertMessageIOS: '...',
pollingOptions: {NfcTagPollingOption.iso14443, NfcTagPollingOption.iso15693, NfcTagPollingOption.iso18092},
onTagDiscovered: (NfcTag tag) {
print(tag);
print(tag.ndef); // You can also read NDEF.
},
);
Stop Session #
NfcManager.instance.stopSession(
alertMessageIOS: [success message string],
errorMessageIOS: [error message string],
);