Flutter plugin for accessing the NFC features on Android and iOS.

Overview

nfc_manager

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).

Setup

Android Setup

iOS Setup

Usage

Handling Session

// Check availability
bool isAvailable = await NfcManager.instance.isAvailable();

// Start Session
NfcManager.instance.startSession(
  onDiscovered: (NfcTag tag) async {
    // Do something with an NfcTag instance.
  },
);

// Stop Session
NfcManager.instance.stopSession();

Handling Platform Tag

The following platform-tag-classes are available:

  • 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)

Obtain an instance by calling the factory constructor from() on the class. For example:

Ndef ndef = Ndef.from(tag);

if (ndef == null) {
  print('Tag is not compatible with NDEF');
  return;
}

// Do something with an Ndef instance

Please see the API Doc for more details.

Real-World-App

See this repo which is a Real-World-App demonstrates how to use this plugin.

Comments
  • iOS ISO15693 read Multiple Blocks

    iOS ISO15693 read Multiple Blocks

    I always get "Invalid Parameters" & "custom Command code must be between 0xA0 to 0xDF"

    What I do: Set<ISO15693RequestFlag> requestFlags = new Set(); requestFlags.add(ISO15693RequestFlag.highDataRate); requestFlags.add(ISO15693RequestFlag.address); Uint8List command = new Uint8List(10); command[0] = (182); command[1] = (51); command[2] = (59); command[3] = (167); command[4] = (0); command[5] = (38); command[6] = (2); command[7] = (224); command[8] = (165); command[9] = (4); Uint8List response = await iso15693.customCommand(requestFlags: requestFlags, commandCode: 23, parameters: command); debugPrint('Response: ' + response.toString());

    equals to the command: 22 23 B6 33 3B A7 00 26 02 E0 A5 04 right?

    But I can't get any response.

    enhancement 
    opened by Lastone17 14
  • Exception: decodeObjectForKey: class

    Exception: decodeObjectForKey: class "NFFieldNotification" not loaded or does not exist

    IOS version: 13.2.3

    Error occurs after initiation of Read/ Write events on both devices.

    [xpc.exceptions] NSXPCConnection: connection to service on pid 85 named com.apple.nfcd.service.corenfc: Exception caught during decoding of received selector didDetectExternalReaderWithNotification:, dropping incoming message.

    Exception: Exception while decoding argument 0 (# 2 of invocation): Exception: decodeObjectForKey: class "NFFieldNotificationECP1_0" not loaded or does not exist

    Note: Events are getting triggered, Ready To scan Popup is disappearing.

    opened by 1993-tensa-g 12
  • NFC transceive fails at second transmission on Android.

    NFC transceive fails at second transmission on Android.

    I try to use the NfcV class to transmit some commands to a corresponding tag. I registered the following function as callback for the onDiscovered events. The result is a correct answer on the first try and an exception on the second try. Did I do it wrong?

    Future callbackFunction(NfcTag tag) async {
      final nfcVtag = NfcV.fromTag(tag);
      final cmd = [0x02, 0x20, 0x00].toList();
      try {
        final answer = await nfcVtag.transceive(Uint8List.fromList(cmd));
        debugPrint('First answer ' + answer.toString());
      } catch (e) {
        debugPrint('Exception on first try: ' + e.toString());
      }
      try {
        final answer = await nfcVtag.transceive(Uint8List.fromList(cmd));
        debugPrint('Second answer ' + answer.toString());
      } catch (e) {
        debugPrint('Exception on second try: ' + e.toString());
      }
    }
    

    Output:

    I/flutter (17066): First answer [0, 167, 19, 240, 84, 5, 0, 3, 101]
    I/flutter (17066): Exception on second try: PlatformException(not_found, Tag is not found., null)
    
    opened by markus-oehme-pg40 9
  • iOS popover cancel button event

    iOS popover cancel button event

    Hi @okadan

    first of all great work!

    I am using your package in a project where I read a NfcTag and later use the tag id to call some server logic. Overall I am using the BLoC-pattern and I am wondering if there is an option to catch the "on cancel"-event when you tap the button on the Nfc-Popover in iOS. I differentiate between two states IsReadyToReadNfc and ReadingNfc. Depending on the state I have a button and want to display either "Start Scanning" or "Scanning..."

    enhancement 
    opened by eddiesTime 6
  • iOS iso7816 sendCommand Response Error

    iOS iso7816 sendCommand Response Error

    I'm working on reading an iso1443-4 card on iOS. It works well on Swift code but failed in the flutter project.

    Code with flutter-nfc-manager

    iso7816Tag.sendCommandRaw(Uint8List.fromList([0x00, 0xA4, 0x04, 0x00, 0x08, 0x50, 0x41, 0x59, 0x2E, 0x54, 0x49, 0x43, 0x4C, 0x00])).then((value) =>
    {
       print("select App response ${value}")
    });
    

    flutter-nfc-manager Response

    flutter: select App response []
    [CoreNFC] 00000002 8001cb40 -[NFCTagReaderSession setAlertMessage:]:90  (null)
    

    The command is correct, it works well in Xcode with swift.

    Code with Swift

    let selectApp : NFCISO7816APDU = NFCISO7816APDU(data: Data.init([0x00, 0xA4, 0x04, 0x00, 0x08, 0x50, 0x41, 0x59, 0x2E, 0x54, 0x49, 0x43, 0x4C, 0x00]))!
                
    session.connect(to: tag0!) { (e: Error?) in tag?.sendCommand(apdu: selectApp, completionHandler: { (data: Data, sw1: UInt8, sw2: UInt8, error: Error?) in
      print("selectApp APDU Result \(data.hexDescription)")
    })
    }
    

    Swift Response

    selectApp APDU Result 6f3484085041592e5449434ca5289f0801029f0c21ffffffffffffffff000000000000000000000000000000002019082400000186a0
    

    Please help to confirm the issues. πŸ™

    opened by whywilson 5
  • Will there be any implementation of getting the UID/ID from an NFC Tag?

    Will there be any implementation of getting the UID/ID from an NFC Tag?

    Hello, I'm trying to make a login app which utilises the UID/ID of an NFC Card/Tag to log the user in. I can obtain the value in Android using nfc_in_flutter (another package) but I cant use that here because it doesn't seem to even register the nfc card being infront of the phone. Only yours (nfc_manager) works and actually detects the card when placed infront of the phone.

    The NFC tag I'm using currently is ISO14443, so I set the polling option to that within session start.

    And so I ask, will there be any implementation of getting UID/ID from NFC tags? Because currently on session start of the NFC Manager, once we hover the nfc tag over, we get back {mifare: {identifier: [4, 40, 252, 242, 37, 94, 129], historicalBytes: [], mifareFamily: 2}, ndef: {isWritable: true, maxSize: 137}} the data received seems to be everything but the ID, which is a bit weird.

    Thanks!

    opened by jarren-meep 5
  • Read data from the sector?

    Read data from the sector?

    Hi,

    I am able to see the information like "id", "nfca", "maxTransceiveLength", "mifareclassic". Under "mifareclassic" there is block count, maxtransceivelength, sectorcount, size and timeout information.

    Are we able to read the data from different sector? I wish to retrieve the information in the card.

    Thanks!

    opened by speedlightwp 5
  • How to open the app when nfc is detected

    How to open the app when nfc is detected

    I am trying to open a certain screen when the nfc is detected , i have tried the workmanager but it didn't work , after reaserch i found this artice but i'm not sure how to use it for my own purpose https://muetsch.io/how-to-receive-sharing-intents-in-flutter.html

    opened by dfourcfive 4
  • Issue with iOS 14.4.1 on iPhone 7

    Issue with iOS 14.4.1 on iPhone 7

    I tried out your demo code and also checked out your demo application on my iPhone 7 iOS 14.4.1 and it is not working.

    2021-03-19 11:28:29.884901+0100 Runner[403:8791] [CoreNFC] 00000002 83700c20 -[NFCHardwareManager queueReaderSession:sessionConfig:completionHandler:]:96 error=Error Domain=NFCError Code=203 "System resource unavailable" UserInfo={NSLocalizedDescription=System resource unavailable} 2021-03-19 11:28:29.885297+0100 Runner[403:8791] [CoreNFC] 00000002 80558870 -[NFCTagReaderSession beginSessionWithConfig:]:365 error:Error Domain=NFCError Code=203 "System resource unavailable" UserInfo={NSLocalizedDescription=System resource unavailable}, errorCode: 0xcb

    This is the exception with your example code.

    opened by torgebauer 4
  • QUESTION: Reading previous write Tag Data

    QUESTION: Reading previous write Tag Data

    Hi, i like to learn about nfc, i use write tag with your sample and get this response: Success to "Ndef Write"

    but when i read the tag i get this:

    {id: [249, 109, 254, 163], nfca: {atqa: [4, 0], maxTransceiveLength: 253, sak: 8, timeout: 618}, mifareclassic: {blockCount: 64, maxTransceiveLength: 253, sectorCount: 16, size: 1024, timeout: 618, type: 0}, ndef: {cachedMessage: {records: [{typeNameFormat: 1, type: [84], identifier: [], payload: [2, 101, 110, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]}, {typeNameFormat: 1, type: [85], identifier: [], payload: [4, 102, 108, 117, 116, 116, 101, 114, 46, 100, 101, 118]}, {typeNameFormat: 2, type: [116, 101, 120, 116, 47, 112, 108, 97, 105, 110], identifier: [], payload: [72, 101, 108, 108, 111]}, {typeNameFormat: 4, type: [99, 111, 109, 46, 101, 120, 97, 109, 112, 108, 101, 58, 109, 121, 116, 121, 112, 101], identifier: [], payload: [109, 121, 100, 97, 116, 97]}]}, canMakeReadOnly: false, isWritable: true, maxSize: 716, type: com.nxp.ndef.mifareclassic}}

    how i do to process the payload to see the info as was wrote?

    thanks for your help!

    opened by alexlovar 4
  • Error build for Iphone 14

    Error build for Iphone 14

    Hello when i want to build my project with iphone 14 which uses NFC_Manager, i obtain this error:

    Swift Compiler Error (Xcode): Stored properties cannot be marked potentially unavailable with '@available'
    /flutter/.pub-cache/hosted/pub.dartlang.org/nfc_manager-3.1.1/ios/Classes/SwiftNfcManagerPlugin.swift:6:3
    

    Any idea ? Thx

    opened by redDwarf03 3
  • Issue when using MifareUltralight.writePage

    Issue when using MifareUltralight.writePage

    W/BpBinder(16057): Slow Binder: BpBinder transact took 622 ms, interface=android.nfc.INfcTag, code=6 oneway=false I/flutter (16057): PlatformException(io_exception, Tag was lost., null, null)

    opened by liamsammut97 0
  • Targeting S+ (version 31 and above)

    Targeting S+ (version 31 and above)

    Hi! Thanks for t his great project I work with nfca tags and my app works fine with android 10 but when I want to run it on android 12, It crashes Caused by: java.lang.IllegalArgumentException: com..: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. E/AndroidRuntime(21272): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. E/AndroidRuntime(21272): at android.app.PendingIntent.checkFlags(PendingIntent.java:382) E/AndroidRuntime(21272): at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465) E/AndroidRuntime(21272): at android.app.PendingIntent.getActivity(PendingIntent.java:451) E/AndroidRuntime(21272): at android.app.PendingIntent.getActivity(PendingIntent.java:415) E/AndroidRuntime(21272): at com.example.coollog.MainActivity.onResume(MainActivity.kt:13) E/AndroidRuntime(21272): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1476) E/AndroidRuntime(21272): at android.app.Activity.performResume(Activity.java:8441) E/AndroidRuntime(21272): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5200)

    opened by Hesam-Taleghani 1
  • Keep listening for cards after the screen is off and on

    Keep listening for cards after the screen is off and on

    Hi, when the app is opened and a session is started and listening for cards if I lock the screen off and on again then the app is no longer listening for cards, to reproduce use this simple app:

    import 'package:flutter/material.dart';
    import 'package:nfc_manager/nfc_manager.dart';
    import 'package:nfc_manager/platform_tags.dart';
    
    void main() {
      runApp(const MaterialApp(
        home: HomeWidget(),
      ));
    }
    
    class HomeWidget extends StatefulWidget {
      const HomeWidget({Key? key}) : super(key: key);
    
      @override
      State<HomeWidget> createState() => _HomeWidgetState();
    }
    
    class _HomeWidgetState extends State<HomeWidget> {
      List<int> cards = [];
    
      void nfcInit() async {
        try {
          bool isAvailable = await NfcManager.instance.isAvailable();
          print("nfc available");
          NfcManager.instance.startSession(
            onDiscovered: (NfcTag tag) async {
              int? rfid;
              MifareClassic? platformtag = MifareClassic.from(tag);
              if (platformtag == null) {
                print('Tag is not compatible with NDEF');
                return;
              }
              setState(() {
                rfid = int.parse(List.from(platformtag.identifier).join(''));
                if (rfid != null) {
                  cards.add(rfid!);
                }
              });
            },
          );
        } catch (e) {
          print('no nfc detected?');
          print(e);
        }
      }
    
      @override
      void initState() {
        // TODO: implement initState
        super.initState();
        nfcInit();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text('test')),
          body: Container(
            color: Colors.blueGrey,
            child: ListView.builder(
              itemCount: cards.length,
              itemBuilder: ((context, index) {
                return Center(
                  child: Text(
                    cards[index].toString(),
                    style: TextStyle(fontSize: 25, color: Colors.white),
                  ),
                );
              }),
            ),
          ),
        );
      }
    }
    

    run this app and test it by reading a card, then lock the screen (while the app is running) and unlock it, if you try to read a card now, then it doesn't read and the sound emitted from the device is different (indicating the session is stopped).

    opened by moham96 0
  • Issue download dependencie

    Issue download dependencie

    when i want to launch the app on an android device i receive the following error ...

    A problem occurred configuring project ':nfc_manager'.
    > Could not resolve all files for configuration ':nfc_manager:classpath'.
       > Could not resolve org.ow2.asm:asm-analysis:7.0.
         Required by:
             project :nfc_manager > com.android.tools.build:gradle:4.1.0
             project :nfc_manager > com.android.tools.build:gradle:4.1.0 > org.ow2.asm:asm-commons:7.0
             project :nfc_manager > com.android.tools.build:gradle:4.1.0 > org.ow2.asm:asm-util:7.0
          > Could not resolve org.ow2.asm:asm-analysis:7.0.
             > Could not get resource 'https://jcenter.bintray.com/org/ow2/asm/asm-analysis/7.0/asm-analysis-7.0.pom'.
                > Could not HEAD 'https://jcenter.bintray.com/org/ow2/asm/asm-analysis/7.0/asm-analysis-7.0.pom'.
                   > Operation timed out (Read failed)
    > Failed to notify project evaluation listener.
       > Could not get unknown property 'android' for project ':nfc_manager' of type org.gradle.api.Project.
       > Could not get unknown property 'android' for project ':nfc_manager' of type org.gradle.api.Project.
    

    if someone can help me

    opened by achersyntechpro 0
Releases(v3.0.0)
Flutter beacons plugin for Android and iOS.

Beacons Flutter plugin to work with beacons. Supports Android API 16+ and iOS 8+. Features: Automatic permission management Ranging Monitoring (includ

Loup 76 Mar 10, 2022
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link Complete Source code (Patreon) In thi

Abu Anwar 197 Sep 27, 2022
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

Andrey 163 Sep 13, 2022
This Android/IOS application intends to help users to get an early notification for slot availability for Covid19 vaccination.

Cowin Slot Reminder Objective: This Android/IOS application intends to help users to get an early notification for slot availability for Covid19 vacci

null 5 Aug 25, 2022
iOS App to Record Daily Sun Intake

Why Suncheck 당신은 ν•˜λ£¨μ— ν•΄λ₯Ό μ–Όλ§ˆλ‚˜ λ³΄λ‚˜μš”? μ½”μ‹œκ΅­μ— λ”μš± μš°μšΈν•˜κ±°λ‚˜ 무기λ ₯ν•œ 건 햇살을 μΆ©λΆ„νžˆ 받지 λͺ»ν•΄μ„œ 일 μˆ˜λ„ μžˆμ–΄μš”. 맀일 단 15λΆ„μ˜ ν–‡μ‚΄λ§ŒμœΌλ‘œ 우리 λ‡Œμ—μ„œλŠ” μš°μšΈμ¦μ„ μ˜ˆλ°©ν•  수 μžˆμ„ 만큼의 μ„Έλ‘œν† λ‹Œμ΄ λΆ„λΉ„λ©λ‹ˆλ‹€. λ§Œμ•½ ν•˜λ£¨ λ™μ•ˆ λ‚΄κ°€ μ–Όλ§ˆλ‚˜

Sohee Kim 13 Jul 16, 2022
Bluetooth plugin for Flutter

Introduction FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps. Alpha version This libr

Paul DeMarco 2.1k Sep 26, 2022
A Flutter plugin for turning your device into a beacon.

Beacon Broadcast plugin for Flutter A Flutter plugin for turning your device into a beacon. Usage To use this plugin, add beacon_broadcast as a depend

Paulina Szklarska 75 Sep 16, 2022
Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Souvik Biswas 177 Sep 4, 2022
null 4 Aug 3, 2022
Vernet - Network Analyzer and Monitoring Tool

Vernet Vernet - Network Analyzer and Monitoring Tool Features Shows Wi-Fi details Scans for devices(or hosts) on network Scans for open ports of targe

null 86 Sep 14, 2022
I have created app to connect printer with bluetooth. And I already fix library bugs

flutter_bluetooth_printer A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Bounphone KOSADA 1 May 11, 2022
Source code and instructions for do-it-yourself projects.

Ammolytics Projects Source code and instructions for do-it-yourself projects. Projects Open Trickler is a Do-It-Yourself, mobile-controlled powder tri

Ammolytics 40 Jul 10, 2022
Flutter library that handles BLE operations for multiple devices.

Flutter reactive BLE library Flutter library that handles BLE operations for multiple devices. Usage The reactive BLE lib supports the following: BLE

Philips Hue 417 Sep 23, 2022
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

intent 500 Sep 19, 2022
A Flutter Template to communicate with an esp32 over bluetooth

Flutter Esp32 Bluetooth Template Changes in android/ [1 if you take the code to an other project, 2 still nessesarely]: Change minSdkVersion from 16 t

0x4d/Martin Loretz 19 Sep 3, 2022
This flutter app will help you to connect to Bluetooth Devices (like, HC-05)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Riyad Al-Ali 1 Jun 5, 2022
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now)

flutter_bluetooth_serial Flutter basic implementation for Classical Bluetooth (only RFCOMM for now). Features The first goal of this project, started

null 0 Apr 13, 2022
Flutter NFC reader plugin for iOS and Android

Flutter NFC Reader & Writer A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and wri

Matteo Crippa 312 Sep 25, 2022
An app for small and medium organizations (SME) manager, with NFC-tag, e-tag and QR code features supported.

BK LAB Manager - an app for group management 1. Getting Started An app for small and medium organizations (SME) manager, with NFC-tag, e-tag and QR co

Andrew Ng 4 Sep 20, 2022