How to solve Tag is not NDEF-compliant in .Net Maui Plugin.NFC?

问题描述 投票:0回答:0

我在 .Net Maui 7 应用程序中使用 Plugin.NFC。

我正在尝试使用 GitHub 上提供的代码编写一些 NFC 卡。

代码工作正常,但每当我使用新卡时,当我试图在上面写东西时,我收到错误:标签不符合 NDEF。

这是我的代码:

async Task Publish()
{               
    try
    {     
        CrossNFC.Current.StartPublishing(true);
    }
    catch (Exception ex)
    {
        await RaiseError(ex.Message);
    }
}

async void Current_OnTagDiscovered(ITagInfo tagInfo, bool format)
{
    if (!CrossNFC.Current.IsWritingTagSupported)
    {
        await RaiseMessage_("Writing cards is not supported by your device");
        return;
    }
    
    try
    {
        NFCNdefRecord record;

        record = new NFCNdefRecord
        {
            TypeFormat = NFCNdefTypeFormat.Mime,
            MimeType = "application/com.companyname.nfcsample",
            Payload = NFCUtils.EncodeToByteArray("Hithere");
        };

        tagInfo.Records = new[] { record };            
        CrossNFC.Current.PublishMessage(tagInfo, false);
        
    }
    catch (Exception Ex)
    {
        await RaiseError("Writing failed\n" + Ex.Message);            
    }
}

我还注意到这种情况只发生在新卡上。如果我拿了一张卡片并使用 NFC 工具 应用程序在上面写了一些东西,那么我就可以使用我的代码在上面写东西。它在我的应用程序上完全可用。

我好像在卡的“初始化”上遗漏了一些东西。

有人知道怎么解决吗?

谢谢。

nfc maui
© www.soinside.com 2019 - 2024. All rights reserved.