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
Requires Mobile Push Notifications add-on
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:
1pubnub.add_channels_to_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
push_typerequired#- Accepted values:
PNPushType.GCM,PNPushType.FCM,PNPushType.APNS,PNPushType.APNS2. channelsrequired#- Channels to enable for push notifications.
device_idrequired#- Device token.
topic#- APNs topic (bundle identifier). Required if
push_typeisPNPushType.APNS2. environment#- APNs environment. Required if
push_typeisPNPushType.APNS2.
Sample code
Add device to channel
1from pubnub.enums import PNPushType
2
3d = pubnub.add_channels_to_push()\
4 .push_type(PNPushType.GCM)\
5 .channels(["ch1", "ch2", "ch3"])\
6 .device_id("deviceId")\
7 .deferred()
8d.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
Requires Mobile Push Notifications add-on
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:
1pubnub.list_push_channels().push_type(PNPushType).device_id(String).topic(String).environment(PNPushEnvironment)
Sample code
List channels for device
1from pubnub.enums import PNPushType
2
3d = pubnub.list_push_channels()\
4 .push_type(PNPushType.GCM)\
5 .device_id("deviceId")\
6 .deferred()
7d.addCallback(my_callback)
Returns
The list_push_channels() operation returns a PNPushListProvisionsResult which contains the following fields:
Channels#- List of
channelsassociated for mobile push notifications.
Remove a device from push notifications channels
Requires Mobile Push Notifications add-on
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:
1pubnub.remove_channels_from_push().push_type(PNPushType).channels(List).device_id(String).topic(String).environment(PNPushEnvironment)
push_typerequired#- Accepted values:
PNPushType.GCM,PNPushType.FCM,PNPushType.APNS,PNPushType.APNS2. channelsrequired#- Channels to disable for push notifications.
device_idrequired#- Device token.
topic#- APNs topic (bundle identifier). Required if
push_typeisPNPushType.APNS2. environment#- APNs environment. Required if
push_typeisPNPushType.APNS2.
Sample code
Remove device from channel
1from pubnub.enums import PNPushType
2
3d = pubnub.remove_channels_from_push()\
4 .push_type(PNPushType.GCM)\
5 .channels("ch1", "ch2", "ch3")\
6 .device_id("deviceId")\
7 .deferred()
8d.addCallback(my_callback)
Returns
The remove_channels_from_push() does not return actionable data. Check status.is_error() on the status object.