Mobile Push Notifications API for PubNub PHP SDK

Mobile Push Notifications feature enables developers to bridge native PubNub publishing with 3rd-party push notification services including Google Android FCM (Firebase Cloud Messaging) and Apple iOS APNs (Apple Push Notification service).

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

To learn more, read about Mobile Push Notifications.

Add Device to Channel

note
Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Enable mobile push notifications on provided set of channels.

Method(s)

To run Adding Device to Channel you can use the following method(s) in the PHP SDK:

$pubnub->addChannelsToPush()
->pushType(PNPushType)
->channels(array)
->deviceId(string)
->sync();
ParameterTypeRequiredDefaultDescription
pushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
channelsArrayYesAdd mobile push notifications on the specified channels.
deviceIdStringYesDevice ID.
environmentStringNodevelopmentEnvironment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2).
topicStringNoNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushGateway set to apns2.

Basic Usage

Add Device to Channel

use PubNub\Enums\PNPushType;

$pubnub->addChannelsToPush()
->pushType(PNPushType::GCM)
->channels(["ch1", "ch2", "ch3"])
->deviceId("deviceId")
->sync();

Add Device to Channel (APNS2)

use PubNub\Enums\PNPushType;

$pubnub->addChannelsToPush()
->pushType(PNPushType::APNS2)
->channels(["ch1", "ch2", "ch3"])
->deviceId("deviceId")
->environment("production")
->topic("bundle-identifier")
->sync();

List Channels For Device

note
Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Request for all channels on which push notification has been enabled using specified pushToken.

Method(s)

To run Listing Channels For Device you can use the following method(s) in the PHP SDK:

$pubnub->listPushProvisions()
->pushType(PNPushType)
->deviceId(string)
->sync();
ParameterTypeRequiredDefaultDescription
pushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
deviceIdStringYesDevice ID.
environmentStringNodevelopmentEnvironment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2).
topicStringNoNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushGateway set to apns2.

Basic Usage

List Channels For Device

$pubnub->arrayPushProvisions()
->pushType(PNPushType::GCM)
->deviceId("deviceId")
->sync();

List Channels For Device(APNS2)

$pubnub->arrayPushProvisions()
->pushType(PNPushType::APNS2)
->deviceId("deviceId")
->topic("myapptopic")
->environment("production")
->sync();

Response

MethodTypeDescription
getChannels()ArrayList of channels associated for mobile push notifications.

Remove Device From Channel

note
Requires Mobile Push Notifications add-on

This method requires that the Mobile Push Notifications add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Disable mobile push notifications on provided set of channels. If nil will be passed as channels then client will remove mobile push notifications from all channels which associated with pushToken.

Method(s)

To run Removing Device From Channel you can use the following method(s) in the PHP SDK:

$pubnub->removeChannelsFromPush()
->pushType(PNPushType)
->channels(string|array)
->deviceId(string)
->sync();
ParameterTypeRequiredDefaultDescription
pushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
channelsString|ArrayYesRemove mobile push notifications from the specified channels.
deviceIdStringYesDevice ID.
environmentStringNodevelopmentEnvironment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2).
topicStringNoNotifications topic name (usually it is bundle identifier of application for Apple platform). Required only if pushGateway set to apns2.

Basic Usage

Remove Device From Channel

use PubNub\Enums\PNPushType;

$pubnub->removeChannelsFromPush()
->pushType(PNPushType::GCM)
->channels(["ch1", "ch2", "ch3"])
->deviceId("deviceId")
->sync();

Remove Device From Channel(APNS2)

use PubNub\Enums\PNPushType;

$pubnub->removeChannelsFromPush()
->pushType(PNPushType::APNS2)
->channels(["ch1", "ch2", "ch3"])
->deviceId("deviceId")
->topic("myapptopic")
->environment("production")
->sync();
Last updated on