将LaunchApp旁边的附加消息发布到NFC标签会使第一个写入的消息被删除

时间:2014-01-21 12:21:44

标签: c# .net nfc ndef

我想写一个关于应该启动哪个应用程序的NFC标签信息,并向其添加一些文本数据。 LaunchApp工作正常,直到我想传输这个附加消息。当我添加其他消息LaunchApp停止工作时。最好在下面的代码中解释:private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId)

如何使LaunchApp工作并将此字符串GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text传递给标记。

  public partial class MainPage : PhoneApplicationPage {
        private long subscribedMessageID, publishedMessageId;
        private ProximityDevice proximityDevice;
        public MainPage() {
            InitializeComponent();
            createTagService();
        }

        private void createTagService() {
            string appId = "{39989b95-a54a-4810-b4ee-35b33265a680}";//HomeSecurityClient Application ID
            string args = "param=test";
            string launchAppMessage = args + "\tWindowsPhone\t" + appId;
            DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf16LE };
            dataWriter.WriteString(launchAppMessage);
            proximityDevice = ProximityDevice.GetDefault();
            proximityDevice.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(), LaunchMesssageTransmitted);
        }

        private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId) {
            sender.StopPublishingMessage(publishedMessageId);
 /*           Deployment.Current.Dispatcher.BeginInvoke(() => {
                DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf8 };
                dataWriter.WriteString(GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text);
                sender.PublishBinaryMessage("Windows:WriteTag.NetworkData", dataWriter.DetachBuffer(), networkDataMessageTransmitted);
            });*/ //IF I UNCOMMENT THIS TO TRANSMITT ADDITIONAL MESSAGE LAUNCHING APP STOPS WORKING

        }
        private void networkDataMessageTransmitted(ProximityDevice sender, long publishedMessageId) {
            sender.StopPublishingMessage(publishedMessageId);
            Deployment.Current.Dispatcher.BeginInvoke(() => {
                MessageBox.Show("The data is written");
            });
            sender.StopPublishingMessage(publishedMessageId);
        }
    }

1 个答案:

答案 0 :(得分:0)

您不能在一个标签上写两条单独的NDEF消息。最后一条消息将始终覆盖以前的任何消息。但是,您可以做的是在一条NDEF消息中将两条记录(LaunchApp记录和您的自定义记录)写入标记。为此,您可以将PublishBinaryMessage()方法与消息类型“NDEF:WriteTag”一起使用。这样您就可以将格式正确的(!)NDEF消息传递给标记。创建格式正确的NDEF消息的方法是使用http://ndef.mopius.com/中的免费NFC库。