Write NDEF message multiple times to same tag?

断了今生、忘了曾经 提交于 2019-11-30 23:34:35

I'm able to write to a tag more than once without separating it from the phone and tapping it again. See following code for example:

ProximityDevice device = ProximityDevice.GetDefault();
device.SubscribeForMessage("WriteableTag", WriteableTagHandler);


private void WriteableTagHandler(ProximityDevice sender, ProximityMessage message)
{
    var message1= Encoding.Unicode.GetBytes("http://1stUrl.com");
    var message2 = Encoding.Unicode.GetBytes("http://secondUrl.com");

    sender.PublishBinaryMessage("WindowsUri:WriteTag", message1.AsBuffer(), (s, e) =>
        {
            s.StopPublishingMessage(e);
            sender.PublishBinaryMessage("WindowsUri:WriteTag", message2.AsBuffer(), (se,r)=>
            {
                se.StopPublishingMessage(r);
            });
        });              
}

EDIT:

I have just checked with two devices, and in fact, it is possible to write-read more than once without separating and tapping the phones again. See the example below, where one device sends 5 messages and the other receives all of them:

Device 1 (sender):

ProximityDevice device = ProximityDevice.GetDefault();

device.DeviceArrived += (e) =>
    {
        for (int i = 1; i <= 5; i++)
        {
            e.PublishMessage("Windows.mySubType", "message " + i.ToString(), (s, m) =>
                {
                    s.StopPublishingMessage(m);
                });
        }
    };

Device 2 (receiver):

ProximityDevice device = ProximityDevice.GetDefault();

device.SubscribeForMessage("Windows.mySubType", (s, e) =>
    {
        Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(e.DataAsString);
            });
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!