IRONSOFTWAREHOME

How to Read and Write Barcode on iOS in .NET MAUI

Curtis Chau
Curtis Chau
Updated: August 2, 2026

.NET MAUI (Multi-platform App UI) builds upon Xamarin.Forms, providing a unified framework for developing cross-platform applications with .NET. It enables developers to create native user interfaces that function seamlessly on Android, iOS, macOS, and Windows, streamlining the app development process.

The BarCode.iOS package brings barcode support to iOS!

IronBarcode iOS Package

The BarCode.iOS package enables barcode features on iOS devices via .NET cross-platform projects. The vanilla BarCode package is not needed.

PM > Install-Package BarCode.iOS

C# NuGet Library for PDF

Install with NuGet

Install-Package BarCode.iOS

Create a .NET MAUI Project

Under the Multiplatform section, select .NET MAUI App and continue.

Create .NET MAUI App project

Include the BarCode.iOS Library

The library can be added in various ways. The easiest is perhaps by using NuGet.

  1. Inside Visual Studio, right-click on "Dependencies > Nuget" and select "Manage NuGet Packages ...".
  2. Select the "Browse" tab and search for "BarCode.iOS".
  3. Select the "BarCode.iOS" package and click on "Add Package".

To prevent issues with other platforms, modify the csproj file to only include the package when targeting the iOS platform. In order to do so:

  1. Right-click on the *.csproj file for your project and select "Edit Project File".

  2. Create a new ItemGroup element as such:

    <ItemGroup Condition="$(TargetFramework.Contains('ios')) == true">
        <PackageReference Include="BarCode.iOS" Version="2025.3.4" />
    </ItemGroup>
    XML
  3. Move the "BarCode.iOS" PackageReference inside the ItemGroup we just created.

The above steps will prevent the "BarCode.iOS" package from being used on platforms such as Android. For that purpose, install BarCode.Android instead.

Design the App Interface

Modify the XAML file to accept input values for generating barcodes and QR codes. Also, include a button to select a document for reading a barcode. Below is an example:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="IronBarcodeMauiIOS.MainPage">
 
    <VerticalStackLayout Padding="20">
        <HorizontalStackLayout>
            <CheckBox x:Name="generatePdfCheckBox" IsChecked="{Binding IsGeneratePdfChecked}" />
            <Label Text="PDF (unchecked for PNG)" VerticalOptions="Center"/>
        </HorizontalStackLayout>
    
        <Entry x:Name="barcodeInput" Placeholder="Enter barcode value..." />
        <Button Text="Generate and save barcode" Clicked="WriteBarcode" />

        <Entry x:Name="qrInput" Placeholder="Enter QR code value..." />
        <Button Text="Generate and save QR code" Clicked="WriteQRcode" />

        <Button
        Text="Read Barcode"
        Clicked="ReadBarcode"
        Grid.Row="0"
        HorizontalOptions="Center"
        Margin="20, 20, 20, 10"/>
        <ScrollView
        Grid.Row="1"
        BackgroundColor="LightGray"
        Padding="10"
        Margin="10, 10, 10, 30">
            <Label x:Name="OutputText"/>
        </ScrollView>
    </VerticalStackLayout>
 
</ContentPage>
XML

Read and Write Barcodes

From the MainPage.xaml code above, we can see that the checkbox determines whether the generated barcode and QR code should be in PDF format. Next, we set the license key. Please use either a trial or paid license key for this step.

The code checks and retrieves the value from the barcodeInput variable, then uses the CreateBarcode method to generate the barcode. Finally, it calls the SaveToDownloadsAsync method, which saves the file appropriately for both Android and iOS.

On iOS, a custom file path is required to export the document to the Files application.

using IronBarCode;
namespace IronBarcodeMauiIOS;
public partial class MainPage : ContentPage
{
    public bool IsGeneratePdfChecked
    {
        get => generatePdfCheckBox.IsChecked;
        set
        {
            generatePdfCheckBox.IsChecked = value;
        }
    }
    public MainPage()
    {
        InitializeComponent();
        IronBarCode.License.LicenseKey = "IRONBARCODE-MYLICENSE-KEY-1EF01";
    }
    
    // Method to generate and save a barcode
    private async void WriteBarcode(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(barcodeInput.Text))
            {
                var barcode = BarcodeWriter.CreateBarcode(barcodeInput.Text, BarcodeEncoding.EAN13);
                // Determine file extension based on checkbox state
                string fileExtension = IsGeneratePdfChecked ? "pdf" : "png";
                string fileName = $"Barcode_{DateTime.Now:yyyyMMddHHmmss}.{fileExtension}";
                byte[] fileData = IsGeneratePdfChecked ? barcode.ToPdfBinaryData() : barcode.ToPngBinaryData();
                // Save the file to the appropriate location
                await SaveToDownloadsAsync(fileData, fileName);
            }
        }
        catch (Exception ex)
        {
            // Log exceptions to debug output
            System.Diagnostics.Debug.WriteLine(ex);
        }
    }

    // Method to generate and save a QR code
    private async void WriteQRcode(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(qrInput.Text))
            {
                var barcode = QRCodeWriter.CreateQrCode(qrInput.Text);
                // Determine file extension based on checkbox state
                string fileExtension = IsGeneratePdfChecked ? "pdf" : "png";
                string fileName = $"QRcode_{DateTime.Now:yyyyMMddHHmmss}.{fileExtension}";
                byte[] fileData = IsGeneratePdfChecked ? barcode.ToPdfBinaryData() : barcode.ToPngBinaryData();
                // Save the file to the appropriate location
                await SaveToDownloadsAsync(fileData, fileName);
            }
        }
        catch (Exception ex)
        {
            // Log exceptions to debug output
            System.Diagnostics.Debug.WriteLine(ex);
        }
    }

    // Method to read a barcode from a file
    private async void ReadBarcode(object sender, EventArgs e)
    {
        try
        {
            var options = new PickOptions
            {
                PickerTitle = "Please select a file"
            };
            var file = await FilePicker.PickAsync(options);
            OutputText.Text = "";
            if (file != null)
            {
                using var stream = await file.OpenReadAsync();
                BarcodeResults result;
                // Determine if the document is a PDF or an image
                if (file.ContentType.Contains("pdf"))
                {
                    result = BarcodeReader.ReadPdf(stream);
                }
                else
                {
                    result = BarcodeReader.Read(stream);
                }
                // Display the results
                string barcodeResult = "";
                int count = 1;
                result.ForEach(x => { barcodeResult += $"barcode {count}: {x.Value}\n"; count++; });
                OutputText.Text = barcodeResult;
            }
        }
        catch (Exception ex)
        {
            // Log exceptions to debug output
            System.Diagnostics.Debug.WriteLine(ex);
        }
    }

    // Method to save file data to the Downloads folder (or Documents on iOS)
    public async Task SaveToDownloadsAsync(byte[] fileData, string fileName)
    {
        // #if IOS
        // Define the custom path you want to save to
        var customPath = "/Users/Iron/Library/Developer/CoreSimulator/Devices/7D1F57F2-1103-46DA-AEE7-C8FC871502F5/data/Containers/Shared/AppGroup/37CD82C0-FCFC-45C7-94BB-FFEEF7BAFF13/File Provider Storage/Document";
        // Combine the custom path with the file name
        var filePath = Path.Combine(customPath, fileName);
        try
        {
            // Create the directory if it doesn't exist
            if (!Directory.Exists(customPath))
            {
                Directory.CreateDirectory(customPath);
            }
            // Save the file to the specified path
            await File.WriteAllBytesAsync(filePath, fileData);
            // Display a success message
            await Application.Current.MainPage.DisplayAlert("Saved", $"File saved to {filePath}", "OK");
        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("Error saving file: " + ex.Message);
        }
        // #endif
    }
}

Lastly, switch the build target to iOS Simulator and run the project.

Run the Project

This will show you how to run the project and use the barcode feature.

Execute .NET MAUI App project

Download .NET MAUI App Project

You can download the complete code for this guide. It comes as a zipped file that you can open in Visual Studio as a .NET MAUI App project.

Click here to download the project.

Frequently Asked Questions

What is the BarCode.iOS package used for?

The BarCode.iOS package is used to enable barcode features on iOS devices within .NET cross-platform projects by providing barcode creation and scanning capabilities.

How can I install the BarCode.iOS package in my project?

You can install the BarCode.iOS package using NuGet in Visual Studio by managing NuGet Packages and searching for 'BarCode.iOS'. Then, add the package to your project.

Can the BarCode.iOS package be used on platforms other than iOS?

No, BarCode.iOS is specifically for iOS platforms. You should modify the csproj file to include it only when targeting iOS. For Android, you should use the BarCode.Android package.

How do I generate a barcode in a .NET MAUI app using IronBarcode?

In a .NET MAUI app, you can generate a barcode by using the `BarcodeWriter.CreateBarcode` method and saving it with `SaveToDownloadsAsync` method after setting the desired output format.

What method is used to read barcodes in a .NET MAUI app?

The `BarcodeReader.Read` method is used to read barcodes from either images or PDF files in a .NET MAUI app, depending on the file type.

How can I switch between generating barcodes in PDF or PNG format?

You can use a checkbox in your app's interface to determine the output format, and then choose either `ToPdfBinaryData` or `ToPngBinaryData` methods accordingly in your code.

What environment is required to run and test a .NET MAUI app with IronBarcode on iOS?

To run and test a .NET MAUI app with IronBarcode on iOS, you should switch the build target to an iOS Simulator and execute the project through Visual Studio.

Is it necessary to use a license key when using IronBarcode in a .NET MAUI app?

Yes, you need to set either a trial or a paid license key in your application's main page by assigning it to `IronBarCode.License.LicenseKey`.

What role does XAML play in designing the app interface for barcode operations?

XAML is used to design the user interface, including buttons and input fields for generating and reading barcodes, as part of the .NET MAUI app development process.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required