导出 (0) 打印
全部展开
信息
您所需的主题如下所示。但此主题未包含在此库中。

ProximityMessage.DataAsString | dataAsString Property

获取文本形式的消息数据。

语法


var dataAsString = proximityMessage.dataAsString;

属性值

类型: String [JavaScript] | System.String [.NET] | Platform::String [C++]

作为文本的消息数据。

备注

DataAsString 属性仅当消息的二进制数据只包含文本 (UTF8) 字符时可用。否则,DataAsString 属性将返回不可预知的结果。不应尝试使用 DataAsString 属性,除非您确定该数据接收为 UTF8 编码字符。使用 PublishMessage 方法可以发送消息为 UTF8 的编码字符。

示例


function id(elementId) {
    return document.getElementById(elementId);
}

var proximityDevice;
var publishedMessageId = -1;
var subscribedMessageId = -1;

function initializeProximityDevice() {
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();

    if (proximityDevice) {
        id("publishMessageButton").addEventListener("click", publishMessage);
        id("subscribeForMessageButton").addEventListener("click", subscribeForMessage);
id("stopSubscribingForMessageButton").addEventListener("click", 
    stopSubScribingForMessage);
id("stopPublishingMessageButton").addEventListener("click", 
    stopPublishingMessage);
    }
    else {
        id("messageDiv").innerHTML += "Failed to initialized proximity device.<br />";
    }
}

function publishMessage() {
    // Stop publishing the current message.
    if (publishedMessageId != -1) {
        proximityDevice.stopPublishingMessage(publishedMessageId);
    }

    publishedMessageId = 
proximityDevice.publishMessage("Windows.SampleMessage", id("messageText").value);
}

function subscribeForMessage() {
    // Only subscribe for the message one time.
    if (subscribedMessageId === -1) {
        subscribedMessageId = 
    proximityDevice.subscribeForMessage("Windows.SampleMessage", messageReceived);
    }
}

function messageReceived(device, message) {
    id("messageDiv").innerHTML += "Message received: " + message.dataAsString + "<br />";
}

    function stopSubscribingForMessage() {
proximityDevice.stopSubscribingForMessage(subscribedMessageId);
    subscribedMessageId = -1;
    }

    function stopPublishingMessage() {
proximityDevice.stopPublishingMessage(publishedMessageId);
    publishedMessageId = -1;
    }


要求

最低支持客户端

Windows 8

最低支持服务器

Windows Server 2012

最低支持电话

Windows Phone 8

命名空间

Windows.Networking.Proximity
Windows::Networking::Proximity [C++]

元数据

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

另请参见

ProximityMessage
接近程度和轻击 (JavaScript)
接近程度和轻击 (C#/VB/C++)
示例
接近程度示例

 

 

显示:
© 2014 Microsoft