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
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();
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
pushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
channels | Array | Yes | Add mobile push notifications on the specified channels. | |
deviceId | String | Yes | Device ID. | |
environment | String | No | development | Environment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2 ). |
topic | String | No | Notifications 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
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();
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
pushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
deviceId | String | Yes | Device ID. | |
environment | String | No | development | Environment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2 ). |
topic | String | No | Notifications 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
Method | Type | Description |
---|---|---|
getChannels() | Array | List of channels associated for mobile push notifications. |
Remove Device From Channel
note
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();
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
pushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
channels | String|Array | Yes | Remove mobile push notifications from the specified channels. | |
deviceId | String | Yes | Device ID. | |
environment | String | No | development | Environment within which device should manage list of channels with enabled notifications (works only if pushGateway set to apns2 ). |
topic | String | No | Notifications 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();
Remove all mobile push notifications
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 from all channels registered with the specified push token.
Method(s)
To run Remove all push channels from device
, you can use the following method(s) in the PHP SDK:
$pubnub->removeAllPushChannelsForDevice()
->pushType(PNPushType)
->deviceId(string)
->sync();
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
pushType | PNPushType | Yes | Not set | Accepted values: PNPushType.GCM , PNPushType.APNS2 . |
deviceId | String | Yes | Device ID. |
Basic Usage
Remove all push channels from device
use PubNub\Enums\PNPushType;
// For APNs2
$pubnub->removeAllPushChannelsForDevice()
->pushType(PNPushType::APNS2)
->deviceId("yourDeviceId")
->sync();
// For FCM
$pubnub->removeAllPushChannelsForDevice()
->pushType(PNPushType::GCM)
->deviceId("yourDeviceId")
->sync();
Response
The sync()
method returns a response indicating the success or failure of the operation. This could be a status code, boolean, or detailed object, depending on the implementation.
$response = $pubnub->removeAllPushChannelsForDevice()
->pushType(PNPushType::APNS2)
->deviceId("yourDeviceId")
->sync();
if ($response->isSuccessful()) {
echo "Successfully removed all push channels from device.";
} else {
echo "Failed to remove push channels. Error: " . $response->getError();
}