Plugin.NFC

[删除(380066935@qq.com或微信通知)]

Plugin.NFC

franckbour/Plugin.NFC: A Cross-Platform NFC (Near Field Communication) plugin to easily read and write NFC tags in your application. (github.com)

A Cross-Platform NFC (Near Field Communication) plugin to easily read and write NFC tags in your Xamarin Forms or .NET MAUI applications.

This plugin uses NDEF (NFC Data Exchange Format) for maximum compatibilty between NFC devices, tag types, and operating systems.

Supported Platforms

PlatformVersionTested on
Android4.4+Google Nexus 5, Huawei Mate 10 Pro, Google Pixel 4a, Google Pixel 6a
iOS11+iPhone 7, iPhone 8

Windows, Mac and Linux are currently not supported. Pull Requests are welcomed!

Setup

Android Specific

  • Add NFC Permission android.permission.NFC and NFC feature android.hardware.nfc in your AndroidManifest.xml
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
  • Add the line CrossNFC.Init(this) in your OnCreate()
protected override void OnCreate(Bundle savedInstanceState)
{
    // Plugin NFC: Initialization before base.OnCreate(...) (Important on .NET MAUI)
    CrossNFC.Init(this);

    base.OnCreate(savedInstanceState);
    [...]
}
  • Add the line CrossNFC.OnResume() in your OnResume()
protected override void OnResume()
{
    base.OnResume();

    // Plugin NFC: Restart NFC listening on resume (needed for Android 10+) 
    CrossNFC.OnResume();
}
  • Add the line CrossNFC.OnNewIntent(intent) in your OnNewIntent()
protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);

    // Plugin NFC: Tag Discovery Interception
    CrossNFC.OnNewIntent(intent);
}

iOS Specific

iOS 13+ is required for writing tags.

An iPhone 7+ and iOS 11+ are required in order to use NFC with iOS devices.

  • Add Near Field Communication Tag Reading capabilty in your Entitlements.plist
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
    <string>NDEF</string>
    <string>TAG</string>
</array>
  • Add a NFC feature description in your Info.plist
<key>NFCReaderUsageDescription</key>
<string>NFC tag to read NDEF messages into the application</string>
  • Add these lines in your Info.plist if you want to interact with ISO 7816 compatible tags
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<string>com.apple.developer.nfc.readersession.iso7816.select-identifiers</string>
  • Add these lines in your Info.plist if you want to interact with Mifare Desfire EV3 compatible tags
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
    <string>com.apple.developer.nfc.readersession.iso7816.select-identifiers</string>
    <string>D2760000850100</string>
</array>