Utility Methods API for Unity SDK
The methods on this page are utility methods that don't fit into other categories.
Cleanup
Cleanup frees up the threads and allows for clean exit.
Method(s)
1Pubnub.CleanUp()
Sample code
Reference code
1
Returns
None
Disconnect
Call the Disconnect method to force the SDK to stop all requests to PubNub server when there are active subscribe channels.
Method(s)
To disconnect the data transmission you can use the following method(s) in Unity SDK.
1Disconnect<T>()
This method doesn't take any arguments.
Sample code
1
Get subscribed channel groups
Returns all the subscribed channel groups in a List of type String.
Method(s)
To Get Subscribe Channel Groups you can use the following method(s) in the Unity SDK:
1List<string> GetSubscribedChannelGroups()
Sample code
Get subscribed channel groups
1
Response
List<String>
1["channelGroup1", "channelGroup2"]
Get subscribed channels
Returns all the subscribed channels in a List of type String.
Method(s)
To Get Subscribed Channels you can use the following method(s) in the Unity SDK:
1List<string> GetSubscribedChannels()
Sample code
Get subscribed channels
1
Response
List<String>
1["channel1", "channel2"]
Reconnect
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 SDK.
1Reconnect<T>(bool resetSubscribeToken)
| Parameter | Description |
|---|---|
resetSubscribeTokenType: bool | Passing true will send zero timetoken upon reconnect. |
Sample code
1
Create push payload
This method creates the push payload for use in the appropriate endpoint calls.
Method(s)
1new MobilePushHelper()
2 .PushTypeSupport(PNPushType[])
3 .Title(string)
4 .Body(string)
5 .Badge(int)
6 .Sound(string)
7 .Apns2Data(List<Apns2Data>)
8 .Custom(Dictionary<PNPushType, Dictionary<string, object>>)
9 .GetPayload()
| Parameter | Description |
|---|---|
PushTypeSupport *Type: PNPushType[] | Push types to build the payload for: APNS, APNS2, FCM, or GCM. Each type adds its own key to the payload (pn_apns for APNS and APNS2, pn_fcm for FCM, pn_gcm for GCM). |
Title *Type: string | Title of the notification. |
BodyType: string | Body text of the notification. |
BadgeType: int | Badge number shown on the app icon. |
SoundType: string | Name of the sound to play when the notification arrives. |
Apns2DataType: List<Apns2Data> | APNS2 delivery settings such as collapseId, expiration, authMethod, and targets (topic, excluded devices, environment). Added under the pn_push key. Used only with APNS2. |
CustomType: Dictionary<PNPushType, Dictionary<string, object>> | Extra key-value data added to the payload of each push type. |
GetPayload *Type: | Builds the payload from the values you set. Returns a Dictionary<string, object>. Throws MissingMemberException if PushTypeSupport or Title is missing. |
Sample code
Create push payload
1
Response
The GetPayload() method returns a Dictionary<string, object> which can be passed directly to the Publish Method's Message parameter.