Mobile Push Notifications API for PubNub Python-Asyncio 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.
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 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 Python SDK:
pubnub.add_channels_to_push().\
push_type(PNPushType).\
channels(List).\
device_id(String).\
topic(String).\
environment(PNPushEnvironment)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
push_type | PNPushType | Yes | n/a | The available push types. Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 |
channels | List | Yes | n/a | The channels to add the mobile push notifications to. |
device_id | String | Yes | n/a | The device ID (token) to associate with the mobile push notifications. |
topic | String | Required for PNPushType.APNS2 | n/a | The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2 . |
environment | String | Required for PNPushType.APNS2 | PNPushEnvironment.DEVELOPMENT | The environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2 . |
Basic Usage
Adding Device to Channel
# for FCM/GCM
from pubnub.enums import PNPushType
envelope = await pubnub.add_channels_to_push()\
.push_type(PNPushType.GCM)\
.channels(["ch1", "ch2", "ch3"])\
.device_id("deviceId")\
.future()
# for APNS2
from pubnub.enums import PNPushType
envelope = await pubnub.add_channels_to_push()\
.push_type(PNPushType.APNS2)\
.channels(["ch1", "ch2", "ch3"])\
show all 19 linesReturns
The add_channels_to_push()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()
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 Python SDK:
pubnub.list_push_channels()
.push_type(PNPushType)
.device_id(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
push_type | PNPushType | Yes | n/a | The available push types. Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 |
device_id | String | Yes | n/a | The device ID (token) to associate with the mobile push notifications. |
topic | String | Required for PNPushType.APNS2 | n/a | The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2 . |
environment | String | Required for PNPushType.APNS2 | PNPushEnvironment.DEVELOPMENT | The environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2 . |
Basic Usage
Listing Channels For Device
# for FCM/GCM
from pubnub.enums import PNPushType
envelope = await pubnub.list_push_channels()\
.push_type(PNPushType.GCM)\
.device_id("deviceId")\
.future()
# for APNS2
from pubnub.enums import PNPushType
envelope = await pubnub.list_push_channels()\
.push_type(PNPushType.APNS2)\
.device_id("deviceId")\
.topic("myapptopic")\
show all 17 linesReturns
The list_push_channels()
operation returns a PNPushListProvisionsResult
which contains the following fields:
Method | Type | Description |
---|---|---|
Channels | List | List of channels associated for mobile 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 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 Python SDK:
pubnub.remove_channels_from_push()
.push_type(PNPushType)
.channels(List)
.device_id(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
push_type | PNPushType | Yes | n/a | The available push types. Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS2 |
channels | List | Yes | n/a | The channels to add the mobile push notifications to. |
device_id | String | Yes | n/a | The device ID (token) to associate with the mobile push notifications. |
topic | String | Required for PNPushType.APNS2 | n/a | The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2 . |
environment | String | Required for PNPushType.APNS2 | PNPushEnvironment.DEVELOPMENT | The environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2 . |
Basic Usage
Removing Device From Channel
# for FCM/GCM
from pubnub.enums import PNPushType
envelope = await pubnub.remove_channels_from_push()\
.push_type(PNPushType.GCM)\
.channels("ch1", "ch2", "ch3")\
.device_id("deviceId")\
.future()
# for APNS2
from pubnub.enums import PNPushType
envelope = await pubnub.remove_channels_from_push()\
.push_type(PNPushType.APNS2)\
.channels("ch1", "ch2", "ch3")\
show all 19 linesReturns
The remove_channels_from_push()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()
.
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.
Description
Disable mobile push notifications from all channels registered with the specified pushToken.
Method(s)
To run Remove all mobile push notifications
, you can use the following method(s) in the Python SDK:
pubnub.remove_device_from_push()
.push_type(PNPushType)
.device_id(String)
.topic(String)
.environment(PNPushEnvironment)
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
push_type | PNPushType | Yes | n/a | The available push types. Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.MPNS , PNPushType.APNS2 |
device_id | String | Yes | n/a | The device ID (token) to associate with the mobile push notifications. |
topic | String | Required for PNPushType.APNS2 | n/a | The topic name for the notification. For the Apple platform, this is the application's bundle identifier. Required only if push_type is set to PNPushType.APNS2 . |
environment | String | Required for PNPushType.APNS2 | PNPushEnvironment.DEVELOPMENT | The environment where the device should manage the list of channels with enabled notifications. Required only if push_type is set to PNPushType.APNS2 . |
Basic Usage
Remove all mobile push notifications
# for FCM/GCM
from pubnub.enums import PNPushType
envelope = await pubnub.remove_device_from_push()\
.push_type(PNPushType.GCM)\
.device_id("deviceId")\
.future()
# for APNS2
from pubnub.enums import PNPushType
envelope = await pubnub.remove_device_from_push()\
.push_type(PNPushType.APNS2)\
.device_id("deviceId")\
.topic("myapptopic")\
show all 17 linesRest Response from Server
The remove_device_from_push()
does not return actionable data, be sure to check the status object on the outcome of the operation by checking the status.is_error()
.