Push Notifications API for PubNub PHP SDK

PubNub's Mobile Push Gateway 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 Gateway, 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 Push Notifications.

Adding Device to Channel

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.

Description

Enable 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 V4 SDK:

$pubnub->addChannelsToPush()->pushType(PNPushType)->channels(array)->deviceId(string)->sync();
ParameterTypeRequiredDefaultDescription
pushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
channelsArrayYesAdd 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

Adding Device to Channel

use PubNub\Enums\PNPushType;

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

Adding 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();

Listing Channels For Device

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.

Description

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 V4 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

Listing Channels For Device

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

Listing Channels For Device(APNS2)

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

Response

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

Removing Device From Channel

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.

Description

Disable push notifications on provided set of channels. If nil will be passed as channels then client will remove 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 V4 SDK:

$pubnub->removeChannelsFromPush()->pushType(PNPushType)->channels(string|array)->deviceId(string)->sync();
ParameterTypeRequiredDefaultDescription
pushTypePNPushTypeYesNot setAccepted values: PNPushType.GCM, PNPushType.APNS2.
channelsString|ArrayYesRemove 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

Removing Device From Channel

use PubNub\Enums\PNPushType;

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

Removing 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