UnityUnity V4 Mobile Push API Reference for Realtime Apps

 

These docs are for PubNub 4.x for Unity which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.x for Unity.

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

PubNub's Mobile Push Gateway feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android GCM (Google Cloud Messaging)/FCM (Firebase Cloud Messaging), Apple iOS APNS (Apple Push Notification Service), and Microsoft Windows Phone MPNS (Microsoft Push Notification Service).

By using the Mobile Push Gateway, developers can eliminate the need for developing, configuring, and maintaining additional server-side components for 3rd-party push notification providers.

Learn more about our Mobile Push Gateway here.


Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications 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.
Enable push notifications on provided set of channels. (This method is deprecated in favor of the corresponding APNS2 method above. Use only for legacy APNS publishing.)
To run Adding Device to Channel you can use the following method(s) in the Unity V4 SDK
  1. ParameterTypeRequiredDefaultsDescription
    ChannelsList<string>YesAdd push notifications on the specified channels.
    DeviceIdstringYesDevice id.
    PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS, PNPushType.MPNS.
    TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
    EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2.
    Accepted values: Development, Production.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult.
pubnub.AddPushNotificationsOnChannels()
	.Channels(new List<string>{"channel2"})
	.DeviceID(<deviceId>)
	.PushType(PNPushType.GCM)
	.Async((result, status) => {
		Debug.Log ("in AddPushNotificationsOnChannels");
		if(status.Error){
			Debug.Log (string.Format(" AddPushNotificationsOnChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
		} else {
			Debug.Log (string.Format("DateTime {0}, In AddPushNotificationsOnChannels, result: {1}", DateTime.UtcNow, result.Message));
		}
	});
The AddPushNotificationsOnChannels() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.IsError().

Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications 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.
Request for all channels on which push notification has been enabled using specified pushToken. (This method is deprecated in favor of the corresponding APNS2 method above. Use only for legacy APNS publishing.)
To run Listing Channels For Device you can use the following method(s) in the Unity V4 SDK
  1. ParameterTypeRequiredDefaultsDescription
    DeviceIDstringYesDevice id.
    PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS, PNPushType.MPNS.
    TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
    EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2.
    Accepted values: Development, Production.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult..
pubnub.AuditPushChannelProvisions()
	.DeviceID(<deviceId>)
	.PushType(PNPushType.GCM)
	.Async((result, status) => {
		Debug.Log ("in AuditPushChannelProvisions");
		if(status.Error){
			Debug.Log (string.Format(" AuditPushChannelProvisions Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
		} else {
			Debug.Log (string.Format("DateTime {0}, In AuditPushChannelProvisions, result: {1}", DateTime.UtcNow, (result.Channels!=null)?string.Join(",", result.Channels.ToArray()):""));	   
		}
	});
The AuditPushChannelProvisions() operation returns a PNPushListProvisionsResult which contains the following operations:
MethodTypeDescription
ChannelsList<string>List of channels associated for push notifications.

Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications 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.
Disable push notifications on provided set of channels.
To run Removing Device From Channel you can use the following method(s) in the Unity V4 SDK
  1. ParameterTypeRequiredDefaultsDescription
    ChannelsList<string>YesRemove push notifications on the specified channels.
    DeviceIDstringYesDevice id.
    PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS, PNPushType.MPNS.
    TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
    EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2.
    Accepted values: Development, Production.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNPushAddChannelResult.
pubnub.RemovePushNotificationsFromChannels()
	.Channels(new List<string> {
		"channel2"
	})
	.DeviceID(<deviceId>)
	.PushType(PNPushType.GCM)
	.Async((result, status) => {
		Debug.Log ("in RemovePushNotificationsFromChannels");
		if( status.Error ){
			Debug.Log(string.Format(" RemovePushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
		} else {
		}
	});
The RemovePushNotificationsFromChannels() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.IsError().

Requires Mobile Push Notifications add-on XRequires that the Mobile Push Notifications 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.
Disable push notifications from all channels which is registered with specified pushToken. (This method is deprecated in favor of the corresponding APNS2 method above. Use only for legacy APNS publishing.)
To run Remove all push notifications you can use the following method(s) in the Unity V4 SDK
  1. ParameterTypeRequiredDefaultsDescription
    DeviceIDstringYesDevice id.
    PushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS, PNPushType.MPNS.
    TopicstringYes if PNPushType is APNS2Not setNotifications topic name (usually it is application's bundle identifier).
    EnvironmentPNPushEnvironmentNoDevelopmentWorks only if PNPushType set to APNS2.
    Accepted values: Development, Production.
    QueryParamDictionary<string, string>OptionalQueryParam accepts a Dictionary object, the keys and values are passed as the query string parameters of the URL called by the API.
    AsyncPNCallbackYesPNCallback of type PNPushRemoveAllChannelsResult.
pubnub.RemoveAllPushNotifications()
	.DeviceID(<deviceId>)
	.PushType(PNPushType.GCM)
	.Async((result, status) => {
		Debug.Log ("in RemoveAllPushNotificationsFromChannels");
		if(status.Error){
			Debug.Log (string.Format("In Example, RemoveAllPushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
		} else {
			Debug.Log (string.Format("DateTime {0}, In RemoveAllPushNotificationsFromChannels, result: {1}", DateTime.UtcNow, result.Message));
		}
	});
The RemoveAllPushNotificationsFromDeviceWithPushToken() does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.isError().