.netmacosmauinfcpackaging

MAUI MacCatalyst can't edit Entitlements.plists for allowing use of Near Field Communication usage


i'm using this PCSC package for reading and writing data of some NFC Tag's.

When i launch my app in debug or release mod everything is working fine until i prepared my app for packaging in MacCatalyst. I need to add an Entitlements.plist file for allowing certain functionnality usage and here's a basic one that i found after following this packaging tutorial.

After adding this file if i launch my app i get an error message where it can't access the smart card resource manager. The Smart card resource manager is not running. on an other mac i just get PCSC.framework/PCSC but i think it's the same problem.

Here's a quick step by step with a simplified example code to reproduce the problem:

  1. Create a new default .NET MAUI App with target fromawork .NET 7.0 i called mine 'pcsc-test'
  2. right click on the solution and install nuget package PCSC
  3. go in MainPage.xaml.cs and replace the code by this sample, don't forget to change the namespace by the one you named your project.
using PCSC;

namespace pcsc_test
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void OnCounterClicked(object sender, EventArgs e)
        {
            try
            {
                var context = ContextFactory.Instance.Establish(SCardScope.System);
                CounterBtn.Text = context.GetReaders().FirstOrDefault("None");
            }
            catch (Exception ex)
            {
                CounterBtn.Text = ex.Message;
            }

            SemanticScreenReader.Announce(CounterBtn.Text);
        }
    }
}

At this point if you launch the app and click on the button you should get the name of the first reader connected on your computer or None if you don't have any. That's the expected behavior, now place to the problem

  1. Go in Platforms>MacCatalyst and create a new file 'Entitlement.plist' and set it's content to:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.network.client</key>
    <true/>
</dict>
</plist>

Now try to launch the app again and click on the button, you should get an error message at the place of the name of the reader. Mine is The Smart card resource manager is not running.. Another problem occurs if you try to add any other parameter in the Entitlements.plist file where it can't launch the app.

If anyone got the same error or is willing to help, it'll be greatly appreciated. Have a great day.


Solution

  • Problem was solved by removing the first authorization of the Entitlements file.

    <key>com.apple.security.app-sandbox</key>
    <true/>