NET MAUI and NFC: Reading and Writing Tags

🚀 Introduction

Near Field Communication (NFC) enables short-range wireless communication between devices and tags. With .NET MAUI (Multi-platform App UI), you can build cross-platform applications that read and write NFC tags on both iOS and Android.

This guide covers the essentials, including setup, permissions, platform-specific implementations, and code examples.


📊 Platform Comparison: iOS vs. Android

Feature Android iOS
NFC Support Broad support (NFC-A, NFC-B, NFC-F, NFC-V, MiFare, etc.) Limited to NDEF (NFC Data Exchange Format) tags only
Background Reading Supported (with intent filters) Only foreground reading (app must be open)
Writing Support Read/Write supported Read/Write supported (for NDEF)
Permissions NFC permission and android.hardware.nfc feature required NFC entitlement and NFCReaderUsageDescription in Info.plistist
APIs Android.Nfc namespace, NfcAdapter CoreNFC framework (NFCNDEFReaderSession)

🛠️ Step 1: Project Setup

1.1 Create a .NET MAUI Project

1.2 Install NFC NuGet Package

Install the CommunityToolkit.Maui (includes NFC capabilities) or a dedicated NFC plugin:

1.3 Configure Permissions

Android:

Add these permissions to Platforms/Android/AndroidManifest.xml:

iOS:

Add the following to Platforms/iOS/Info.plist:


📖 Step 2: Reading NFC Tags

2.1 Create a Shared Interface

2.2 Android Implementation

2.3 iOS Implementation

2.4 Register Services in MauiProgram.cs


✍️ Step 3: Writing NFC Tags

3.1 Android Write Implementation

3.2 iOS Write Implementation


🔧 Step 4: UI for Reading/Writing

4.1 XAML Layout

4.2 Code-Behind Logic


⚠️ Step 5: Handling Platform-Specific Quirks

Android:

  • Enable NFC in device settings.
  • Handle OnNewIntent to capture tag events.

iOS:

  • App must be in foreground.
  • Only supports NDEF format.
  • Requires physical iOS device (no simulator support).

🔗 References


🎯 Conclusion

NET MAUI provides a robust framework for building cross-platform NFC applications. While Android offers more flexibility with various tag types and background reading, iOS remains restrictive with NDEF-only support and foreground reading.

By using platform-specific implementations and a shared interface, you can create seamless NFC experiences for both ecosystems.

An unhandled error has occurred. Reload 🗙