Mobile Push Notifications API for Python-Twisted SDK
Deprecated
NOTICE: Based on current web trends and our own usage data, PubNub's Python Twisted SDK is deprecated as of May 1, 2019. Deprecation means we will no longer be updating the Python Twisted SDK but will continue to support users currently using it. Please feel free to use our other Python SDK offerings as they will continue to be supported and maintained. If you would like to use the Python Twisted SDK specifically, we would love to work with you on keeping this project alive!
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).
To learn more, read about Mobile Push Notifications.
Add a device to a push notifications channel
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Enable mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Python-Twisted SDK:
pubnub.add_channels_to_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter | Description |
---|---|
push_type *Type: PNPushType Default: n/a | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS , PNPushType.APNS2 . |
channels *Type: List Default: n/a | Channels to enable for push notifications. |
device_id *Type: String Default: n/a | Device token. |
topic Type: String Default: n/a | APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2 . |
environment Type: String Default: PNPushEnvironment.DEVELOPMENT | APNs environment. Required if push_type is PNPushType.APNS2 . |
Sample code
Add device to channel
from pubnub.enums import PNPushType
d = pubnub.add_channels_to_push()\
.push_type(PNPushType.GCM)\
.channels(["ch1", "ch2", "ch3"])\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The add_channels_to_push()
does not return actionable data. Check status.is_error()
on the status object.
List push notifications channels for a device
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
List channels that have push notifications enabled for the specified device token.
Method(s)
Use the following method(s) in the Python-Twisted SDK:
pubnub.list_push_channels().push_type(PNPushType).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter | Description |
---|---|
push_type *Type: PNPushType Default: n/a | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS , PNPushType.APNS2 . |
device_id *Type: String Default: n/a | Device token. |
topic Type: String Default: n/a | APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2 . |
environment Type: String Default: PNPushEnvironment.DEVELOPMENT | APNs environment. Required if push_type is PNPushType.APNS2 . |
Sample code
List channels for device
from pubnub.enums import PNPushType
d = pubnub.list_push_channels()\
.push_type(PNPushType.GCM)\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The list_push_channels()
operation returns a PNPushListProvisionsResult
which contains the following fields:
Method | Description |
---|---|
Channels Type: List | List of channels associated for mobile push notifications. |
Remove a device from push notifications channels
note
Enable Mobile Push Notifications for your key in the Admin Portal. See how to enable add-on features.
Disable mobile push notifications on a set of channels.
Method(s)
Use the following method(s) in the Python-Twisted SDK:
pubnub.remove_channels_from_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
Parameter | Description |
---|---|
push_type *Type: PNPushType Default: n/a | Accepted values: PNPushType.GCM , PNPushType.FCM , PNPushType.APNS , PNPushType.APNS2 . |
channels *Type: List Default: n/a | Channels to disable for push notifications. |
device_id *Type: String Default: n/a | Device token. |
topic Type: String Default: n/a | APNs topic (bundle identifier). Required if push_type is PNPushType.APNS2 . |
environment Type: String Default: PNPushEnvironment.DEVELOPMENT | APNs environment. Required if push_type is PNPushType.APNS2 . |
Sample code
Remove device from channel
from pubnub.enums import PNPushType
d = pubnub.remove_channels_from_push()\
.push_type(PNPushType.GCM)\
.channels("ch1", "ch2", "ch3")\
.device_id("deviceId")\
.deferred()
d.addCallback(my_callback)
Returns
The remove_channels_from_push()
does not return actionable data. Check status.is_error()
on the status object.