SelectWindows Phone 8 Publish & Subscribe API Reference for Realtime Apps

These docs are for version 3.8.7 of the Windows Phone 8 SDK. To check out the docs for the latest version Click Here.
 

PubNub 4.0 for C# is our latest and greatest! Please click here for our PubNub 4.0 for C# docs and SDK.

PubNub 3.x for C# will encounter End Of Life (EOL) Aug 1st, 2018. All users currently on 3.x should begin migrating to 4.x. The 3.x SDK will continue to work. We will no longer support it and if you run into an issue, we will request that you upgrade to the latest version before solving the issue.

If you have questions about the PubNub for C# SDK, please contact us at support@pubnub.com.

The publish() function is used to send a message to all subscribers of a channel. To publish a message you must first specify a valid publishKey at initialization. A successfully published message is replicated across the PubNub Real-Time Network and sent simultaneously to all subscribed clients on a channel.

Messages in transit can be secured from potential eavesdroppers with SSL/TLS by setting ssl to true during initialization.

Publish Anytime

It is not required to be subscribed to a channel in order to publish to that channel.

Message Data:

The message argument can contain any JSON serializable data, including: Objects, Arrays, Ints and Strings. data should not contain special Windows Phone 8 classes or functions as these will not serialize. String content can include any single-byte or multi-byte UTF-8 character.

 
Do Not JSON serialize!
It is important to note that you should not JSON serialize when sending signals/messages via PUBNUB. Why? Because the serialization is done for you automatically. Instead just pass the full object as the message payload. PubNub takes care of everything for you.
Message Size:

The maximum number of characters per message is 32 KiB by default. The maximum message size is based on the final escaped character count, including the channel name. An ideal message size is under 1800 bytes which allows a message to be compressed and sent using single IP datagram (1.5 KiB) providing optimal network performance.

If the message you publish exceeds the configured size, you will receive the following message:

Message Too Large Error
["PUBLISHED",[0,"Message Too Large","13524237335750949"]]

For further details please check: https://support.pubnub.com/support/solutions/articles/14000113049-calculating-message-payload-size-before-publish.

Message Publish Rate:

Messages can be published as fast as bandwidth conditions will allow. There is a soft limit based on max throughput since messages will be discarded if the subscriber cannot keep pace with the publisher.

For example, if 200 messages are published simultaneously before a subscriber has had a chance to receive any messages, the subscriber may not receive the first 100 messages because the message queue has a limit of only 100 messages stored in memory.

Publishing to Multiple Channels:

It is not possible to publish a message to multiple channels simultaneously. The message must be published to one channel at a time.

Publishing Messages Reliably:

There are some best practices to ensure messages are delivered when publishing to a channel:

  • Publish to any given channel in a serial manner (i.e. not concurrently).
  • Check that the return code is success (e.g. [1,"Sent","136074940..."])
  • Publish the next message only after receiving a success return code.
  • If a failure code is returned ([0,"blah","<timetoken>"]), retry the publish.
  • Avoid exceeding the in-memory queue's capacity of 100 messages. An overflow situation (aka missed messages) can occur if slow subscribers fail to keep up with the publish pace in a given period of time.
  • Throttle publish bursts in accordance with your app's latency needs e.g. Publish no faster than 5 msgs per second to any one channel.
To Publish a message you can use the following method(s) in the Windows Phone 8 SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel name to publish messages to.
    messageobjectYesThe message
    userCallbackCallback Method of Type objectYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies channel name to publish messages to.
    messageobjectYesThe message
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelstringYesSpecifies channel name to publish messages to.
    messageobjectYesThe message
    storeInHistoryboolYesIf true the messages are stored in history, default true
    userCallbackCallback Method of Type objectYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelstringYesSpecifies channel name to publish messages to.
    messageobjectYesThe message.
    storeInHistoryboolYesIf true the messages are stored in history.

    Default true
    userCallbackCallback Method of Type TYesThis callback is called on success event.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.

Publish a message to a channel:

pubnub.Publish<string>(
      channel="my_channel",
      publishMsg="Hello from the PubNub C# SDK!",
      DisplayReturnMessage,
      DisplayErrorMessage
);
void DisplayReturnMessage(string result)
{
    Console.WriteLine("PUBLISH STATUS CALLBACK");
    Console.WriteLine(result);
}
void DisplayErrorMessage(PubnubClientError pubnubError) {
    Console.WriteLine(pubnubError.StatusCode);
}
 
Before running the above publish example, either using the Debug Console, or in a separate script running in a separate terminal window, subscribe to the same channel that is being published to.
The function returns the following formatted response:
[1, "Sent", "13769558699541401"]
  1. pubnub.EnableJsonEncodingForPublish = false;
    object message = "{'operation':'ReturnData','channel':'Mobile1','sequenceNumber':0,'data':['ping 1.0.0.1']}";
    serializedObjectMessageForPublish = message.ToString();
    pubnub.Publish<string>(channel, message, ReturnSuccessSerializedObjectMessageForPublishCallback, DummyErrorCallback);
This function causes the client to create an open TCP socket to the PubNub Real-Time Network and begin listening for messages on a specified channel. To subscribe to a channel the client must send the appropriate subscribeKey at initialization.
By default a newly subscribed client will only receive messages published to the channel after the subscribe() call completes.
 
You can be notified of connectivity via the connect callback. By waiting for the connect callback to return before attempting to publish, you can avoid a potential race condition on clients that subscribe and immediately publish messages before the subscribe has completed.
Using Windows Phone 8 SDK, if a client becomes disconnected from a channel, it can automatically attempt to reconnect to that channel and retrieve any available messages that were missed during that period by setting restore to true. By default a client will attempt to reconnect after exceeding a 320 second connection timeout.
 Unsubscribing from all channels, and then subscribing to a new channel Y is not the same as subscribing to channel Y and then unsubscribing from the previously-subscribed channel(s). Unsubscribing from all channels resets the last-received timetoken and thus, there could be some gaps in the subscription that may lead to message loss.
To Subscribe to a channel you can use the following method(s) in the Windows Phone 8 SDK:
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies the channel to subscribe to. It is possible to specify multiple channels. See Examples for more info.
    subscribeCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientErrorYesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to subscribe to. It is possible to specify multiple channels. See Examples for more info
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to subscribe to.
    subscribeCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelsStringYesSpecifies the channel to subscribe to. It is possible to specify multiple channels. See Examples for more info.
    subscribeCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelsstringYesSpecifies the channel to subscribe to. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to subscribe to.
    subscribeCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
Subscribe to a channel:
pubnub.Subscribe<string>(
   "my_channel",
    DisplaySubscribeReturnMessage,
    DisplaySubscribeConnectStatusMessage,
    DisplayErrorMessage
);
void DisplaySubscribeReturnMessage(string result) {
    Console.WriteLine("SUBSCRIBE REGULAR CALLBACK:"); 
    Console.WriteLine(result);
    if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
            {
                List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                if (deserializedMessage != null && deserializedMessage.Count > 0)
                {
                    object subscribedObject = (object)deserializedMessage[0];
                    if (subscribedObject != null)
                    {
                        //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                        string resultActualMessage = pubnub.JsonPluggableLibrary.SerializeToJsonString(subscribedObject);
                   }
                }
            }
}
void DisplaySubscribeConnectStatusMessage(string result)
{
    Console.WriteLine("SUBSCRIBE CONNECT CALLBACK");
}
void DisplayErrorMessage(PubnubClientError pubnubError) {
    Console.WriteLine(pubnubError.StatusCode);
}
The output below demonstrates the response format to a successful call:
[[], "Time Token"]
  1. pubnub.Subscribe<string>(
       "my_channel",
        DisplaySubscribeReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplayErrorMessage
    );
    void DisplaySubscribeReturnMessage(string result) {
        Console.WriteLine("SUBSCRIBE REGULAR CALLBACK:"); 
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object subscribedObject = (object)deserializedMessage[0];
                        if (subscribedObject != null)
                        {
                            //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                            string resultActualMessage = pubnub.JsonPluggableLibrary.SerializeToJsonString(subscribedObject);
                       }
                    }
                }
    }
    void DisplaySubscribeConnectStatusMessage(string result)
    {
        Console.WriteLine("SUBSCRIBE CONNECT CALLBACK");
    }
    void DisplayErrorMessage(PubnubClientError pubnubError) {
        Console.WriteLine(pubnubError.StatusCode);
    }
  2. Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    It is possible to subscribe to more than one channel over a single TCP socket by taking advantage of Multiplexing feature. See the Multiplexing section for more info on this feature as well as the examples below using a list or an array to specify channel name.
    pubnub.Subscribe <string>(
        "my_channel_1,my_channel_2",
        DisplaySubscribeReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplayErrorMessage
    );
    void DisplaySubscribeReturnMessage(string result) {
        Console.WriteLine("SUBSCRIBE REGULAR CALLBACK:"); 
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object subscribedObject = (object)deserializedMessage[0];
                        if (subscribedObject != null)
                        {
                            //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                            string resultActualMessage = pubnub.JsonPluggableLibrary.SerializeToJsonString(subscribedObject);
                       }
                    }
                }
    }
    void DisplaySubscribeConnectStatusMessage(string result) {
    	Console.WriteLine("SUBSCRIBE CONNECT CALLBACK");
    }
    void DisplayErrorMessage(PubnubClientError pubnubError) {
    	Console.WriteLine(pubnubError.StatusCode);
    }
    string[] arrChannels = {
    	"my_channel_1", "my_channel_2", "my_channel_3"
    }
    string commaDelimitedChannel = string.Join(",", arrChannels);
    pubnub.Subscribe <string>(
        channel: commaDelimitedChannel,
        DisplaySubscribeReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplayErrorMessage
    );
    
    // NOTE: DisplaySubscribeReturnMessage, DisplaySubscribeConnectStatusMessage, and DisplayErrorMessage are callback methods
  3. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    For any given channel there is an associated Presence channel. You can subscribe directly to the channel by appending -pnpres to the channel name. For example the channel named my_channel would have the presence channel named my_channel-pnpres.
    pubnub.Presence<string>(
        channel = "my_channel",
        DisplayPresenceReturnMessage,
        DisplayPresenceConnectStatusMessage,
        DisplayErrorMessage1);
    
    void DisplayPresenceReturnMessage(string result) {
    	Console.WriteLine("PRESENCE REGULAR CALLBACK:");
    	Console.WriteLine(result);
    }
    void DisplayPresenceConnectStatusMessage(string result) {
    	Console.WriteLine("PRESENCE CONNECT CALLBACK:");
    	Console.WriteLine(result);
    }
    void DisplayErrorMessage1(PubnubClientError pubnubError) {
    	Console.WriteLine(pubnubError.StatusCode);
    }
    
    {
    	"action": "join",
    	"timestamp": 1345546797,
    	"uuid": "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
    	"occupancy": 2
    }
    
    {
        "action" : "leave",
        "timestamp" : 1345549797,
        "uuid" : "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
        "occupancy" : 1
    }
    
    {
    	"action": "timeout",
    	"timestamp": 1345549797,
    	"uuid": "76c2c571-9a2b-d074-b4f8-e93e09f49bd",
    	"occupancy": 0
    }
    
    
    {
    	"action": "state-change",
    	"uuid": "76c2c571-9a2b-d074-b4f8-e93e09f49bd",
    	"timestamp": 1345549797,
    	"data": {
    		"isTyping": true
    	}
    }
    
    
    {
    	"action":"interval",
    	"timestamp":1474396578,
    	"occupancy":2
    }
    

    When a channel is in interval mode with presence_deltas pnconfig flag enabled, the interval message may also include the following fields which contain an array of changed UUIDs since the last interval message.

    • joined
    • left
    • timedout

    For example, this interval message indicates there were 2 new UUIDs that joined and 1 timed out UUID since the last interval:

    
    {
        "action" : "interval",
        "occupancy" : <# users in channel>,
        "timestamp" : <unix timestamp>,
        "joined" : ["uuid2", "uuid3"],
        "timedout" : ["uuid1"]
    }
    

    If the full interval message is greater than 30KB (since the max publish payload is ∼32KB), none of the extra fields will be present. Instead there will be a here_now_refresh boolean field set to true. This indicates to the user that they should do a hereNow request to get the complete list of users present in the channel.

    
    {
        "action" : "interval",
        "occupancy" : <# users in channel>,
        "timestamp" : <unix timestamp>,
        "here_now_refresh" : true
    }
    
  4. Requires Presence add-on XRequires that the Presence add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
     Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. Not setting the UUID can significantly impact your billing if your account uses the Monthly Active Users (MAUs) based pricing model, and can also lead to unexpected behavior if you have Presence enabled.
    pubnub.Subscribe <string>
    (
        "my_channel",
        DisplaySubscribeReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplayErrorMessage
    );
    void DisplaySubscribeReturnMessage(string result) {
        Console.WriteLine("SUBSCRIBE REGULAR CALLBACK:"); 
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object subscribedObject = (object)deserializedMessage[0];
                        if (subscribedObject != null)
                        {
                            //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                            string resultActualMessage = pubnub.JsonPluggableLibrary.SerializeToJsonString(subscribedObject);
                       }
                    }
                }
    }
    void DisplaySubscribeConnectStatusMessage(string result) {
        Dictionary <string, object> dict = new Dictionary<string, object> ();
        dict.Add("full", "Robert Plant");
        dict.Add("age", 67);
        dict.Add("country", "UK");
        dict.Add("appstate", "foreground");
        dict.Add("latlong", "51.5072° N, 0.1275° W");
    
        //JSON serialize the message, using Newtonsoft.Json for this example 
        string jsonUserState = Newtonsoft.Json.JsonConvert.SerializeObject(d);
    
        pubnub.SetUserState <string>("my_channel", "", jsonUserState, userCallback, errorCallback);
        Console.WriteLine("SUBSCRIBE CONNECT CALLBACK");
    }
    void DisplayErrorMessage(PubnubClientError pubnubError) {
    	Console.WriteLine(pubnubError.StatusCode);
    }
  5. Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    pubnub.Subscribe<string>("", channelGroup, DisplaySubscribeReturnMessage, DisplaySubscribeConnectStatusMessage, DisplayErrorMessage);
  6. Requires Stream Controller and Presence add-on XRequires that both Stream Controller and Presence add-ons are enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    pubnub.Presence<string>("", channelGroup, DisplaySubscribeReturnMessage, DisplaySubscribeConnectStatusMessage, DisplayErrorMessage);
    
When subscribed to a single channel, this function causes the client to issue a leave from the channel and close any open socket to the PubNub Network. For multiplexed channels, the specified channel(s) will be removed and the socket remains open until there are no more channels remaining in the list.
 Unsubscribing from all channels, and then subscribing to a new channel Y is not the same as subscribing to channel Y and then unsubscribing from the previously-subscribed channel(s). Unsubscribing from all channels resets the last-received timetoken and thus, there could be some gaps in the subscription that may lead to message loss.
To Unsubscribe from a channel you can use the following method(s) in the Windows Phone 8 SDK:
  1. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to unsubscribe from.
    subscribeCallbackCallback Method of Type TYesThis callback is called on success
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type TYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to unsubscribe from.
    subscribeCallbackCallback Method of Type objectYesThis callback is called on success.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type objectYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    subscribeCallbackCallback Method of Type TYesThis callback is called on success.
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type TYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    subscribeCallbackCallback Method of Type objectYesThis callback is called on success.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type objectYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
Unsubscribe from a channel:
pubnub.Unsubscribe<string>(
    channel="my_channel",
    DisplayReturnMessage,
    DisplaySubscribeConnectStatusMessage,
    DisplaySubscribeDisconnectStatusMessage,
    DisplayErrorMessage
);
The output below demonstrates the response to a successful call:
{
	"action" : "leave"
}
  1. Requires Stream Controller add-on XRequires that the Stream Controller add-on is enabled for your key. See this page on enabling add-on features on your keys:

    http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
    pubnub.Unsubscribe <string>(
        channel = "chan4,chan6,chan7",
        DisplayReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplaySubscribeDisconnectStatusMessage,
        DisplayErrorMessage
    );
    string[] arrChannels = {
    	"chan1", "chan2", "chan3"
    }
    string commaDelimitedChannel = string.Join(",", arrChannels);
    
    pubnub.Unsubscribe <string>(
        channel: commaDelimitedChannel,
        DisplayReturnMessage,
        DisplaySubscribeConnectStatusMessage,
        DisplaySubscribeDisconnectStatusMessage,
        DisplayErrorMessage
    );
    // NOTE: DisplayReturnMessage, DisplaySubscribeConnectStatusMessage, DisplaySubscribeDisconnectStatusMessage and DisplayErrorMessage are callback methods
    
    {
    	"action" : "leave"
    }
    
This function is used to subscribe to the presence channel.
Using Windows Phone 8 SDK, if a client becomes disconnected from a channel, it can automatically attempt to reconnect to that channel and retrieve any available messages that were missed during that period by setting restore to true. By default a client will attempt to reconnect after exceeding a 320 second connection timeout.
To do Presence you can use the following method(s) in the Windows Phone 8 SDK
  1. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to subscribe to presence channel. It is possible to specify multiple channels. See Examples for more info.
    presenceCallback Callback Method of Type TYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to subscribe to presence channel. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be provided.Specifies the channelGroup to subscribe to.
    presenceCallback Callback Method of Type TYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to subscribe to presence channel. It is possible to specify multiple channels. See Examples for more info.
    presenceCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelStringYesSpecifies the channel to subscribe to presence channel. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be provided.Specifies the channelGroup to subscribe to.
    presenceCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
Subscribe to the presence channel:
For any given channel there is an associated Presence channel. You can subscribe directly to the channel by appending -pnpres to the channel name. For example the channel named my_channel would have the presence channel named my_channel-pnpres
pubnub.Presence<string>(
    channel = "my_channel",
    DisplayPresenceReturnMessage,
    DisplayPresenceConnectStatusMessage,
    DisplayErrorMessage1);

void DisplayPresenceReturnMessage(string result) {
	Console.WriteLine("PRESENCE REGULAR CALLBACK:");
	Console.WriteLine(result);
}
void DisplayPresenceConnectStatusMessage(string result) {
	Console.WriteLine("PRESENCE CONNECT CALLBACK:");
	Console.WriteLine(result);
}
void DisplayErrorMessage1(PubnubClientError pubnubError) {
	Console.WriteLine(pubnubError.StatusCode);
}
The output below demonstrates the response format to a successful call:

{
	"action": "join",
	"timestamp": 1345546797,
	"uuid": "175c2c67-b2a9-470d-8f4b-1db94f90e39e",
	"occupancy": 2
}
This function lets you stop monitoring the presence of the channel(s). The channel(s) will be removed and the socket remains open until there are no more channels remaining in the list.
To Unsubscribe from Presence of a channel you can use the following method(s) in the Windows Phone 8 SDK
  1. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to unsubscribe from.
    presenceCallbackCallback Method of Type TYesThis callback is called on success
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type TYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    presenceCallbackCallback Method of Type TYesThis callback is called on success
    connectCallbackCallback Method of Type TYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type TYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    channelGroupstringEither channel or channelGroup should be providedSpecifies the channelGroup to unsubscribe from.
    presenceCallbackCallback Method of Type objectYesThis callback is called on success
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type objectYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  4. ParameterTypeRequiredDescription
    channelstringYesSpecifies the channel to unsubscribe from. It is possible to specify multiple channels. See Examples for more info.
    presenceCallbackCallback Method of Type objectYesThis callback is called on success
    connectCallbackCallback Method of Type objectYesThis callback is called on a successful connection to the PubNub cloud.
    disconnectCallbackCallback Method of Type objectYesThis callback is called on a successful disconnection from the PubNub cloud.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
Unsubscribe from the presence channel:
pubnub.PresenceUnsubscribe<string>(channel:"my_channel", channelGroup:"", presenceCallback:DisplayReturnMessage, connectCallback:DisplayPresenceConnectStatusMessage, disconnectCallback:DisplayPresenceDisconnectStatusMessage, errorCallback:DisplayErrorMessage);
The output below demonstrates the response to a successful call:

{
    "action": "leave"
}