Utility Methods API for PubNub Unity SDK

The methods on this page are utility methods that don't fit into other categories.

CleanUp

Description

Destroy frees up the threads and allows for clean exit.

Method(s)

CleanUp()

Basic Usage

pubnub.CleanUp();

Returns

None

Reconnect

Description

Call the reconnect method to force the SDK to try and reach out PubNub.

Method(s)

To reconnect the data you can use the following method(s) in Unity V4 SDK.

Reconnect()

Basic Usage

pubnub.Reconnect();

Time

Description

This function will return a 17 digit precision Unix epoch.

Algorithm constructing the timetoken

The timetoken is constructed using the following algorithm:

timetoken = (Unix epoch time in seconds) * 10000000

Example of creating a timetoken for a specific time and date

08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000

Method(s)

To fetch Time you can use the following method(s) in Unity V4 SDK:

pubnub.Time().Async()
ParameterTypeRequiredDescription
AsyncPNCallbackYesPNCallback of type PNTimeResult

Basic Usage

Get PubNub Timetoken

pubnub.Time()
.Async((result, status) => {
if (status.Error) {
Debug.Log(string.Format("Time Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
} else {
Debug.Log(string.Format("DateTime {0}, In Example, result: {1}", DateTime.UtcNow ,result.TimeToken));
}
});

Returns

The Time() operation returns a PNTimeResult which contains the following operations:

MethodTypeDescription
TimetokenlongReturns a long representation of current timetoken.

Create Push Payload

Description

This method creates the push payload for use in the appropriate endpoint calls.

Method(s)

CreatePushPayloadHelper().SetAPNSPayload(PNAPSData, List<PNAPNS2Data>).SetFCMPayload(PNFCMData).SetCommonPayload(Dictionary<string, object>).BuildPayload()
ParameterTypeRequiredDescription
SetAPNSPayloadPNAPSDataOptionalSet APNS Payload. Associated APNS devices will receive only the data within the pn_apns key.
List<PNAPNS2Data>OptionalSet APNS2 Payload. Associated APNS devices will receive only the data within the pn_push key.
SetFCMPayloadPNFCMDataOptionalSet FCM Payload. Associated FCM devices will receive only the data within the pn_gcm key.
SetCommonPayloadDictionary<string, object>OptionalSet Common Payload. Native PubNub subscribers will receive the entire object literal, including the pn_apns, pn_gcm, and common payload.
BuildPayloadYesBuilds the payload from the values set using the parameters. Returns a Dictionary<string, object>

Basic Usage

Create Push Payload

CreatePushPayloadHelper cpph = new CreatePushPayloadHelper();
PNAPSData aps = new PNAPSData();
aps.Alert = "alert";
aps.Badge = 1;
aps.Sound = "ding";
aps.Custom = new Dictionary<string, object>(){
{"aps_key1", "aps_value1"},
{"aps_key2", "aps_value2"},
};

PNAPNSData apns = new PNAPNSData();
apns.APS = aps;
apns.Custom = new Dictionary<string, object>(){
{"apns_key1", "apns_value1"},
{"apns_key2", "apns_value2"},
show all 84 lines

Response

The CreatePushPayloadHelper() operation returns a Dictionary<string, object> which can be passed directly to the Publish Method's Message parameter.

Last updated on