Your browser doesn't support the features required
by impress.js, so you are presented with a simplified version
of this presentation.
For the best experience please use the latest Chrome
or Safari browser. Firefox 10 and Internet Explorer 10
should also handle it.
Sending Push Notifications With Urban Airship's Python Wrapper
by
Matthew Makai
Presented to DC Python
Excella Consulting
April 3, 2012
Exponential mobile growth
Phones engage people in ways desktops cannot
New engagement type: push notifications
Push Notifications
iOS 4
iOS 5
Android
What are push notifications good for?
Games
Time-sensitive Discounts
Politics
After figuring out appropriate use cases for push
notifications, how do we build the infrastructure to send them?
Urban Airship
What's an "Urban Airship"?
Apple Push Notification Service
Android C2DM
BlackBerry Push Service
Windows Mobile
Urban Airship's RESTful API
https://go.urbanairship.com/api/[action]
POST https://go.urbanairship.com/api/push/
GET https://go.urbanairship.com/api/ \
device_tokens/[tokens]/
POST https://go.urbanairship.com/api/push/batch/
Register a Device
PUT https://go.urbanairship.com/api/ \
device_tokens/FE66489F304DC75B8D6E8200DFF \
8A456E8DAEACEC428B427E9518741C92C6660
Send a Push Notification
POST https://go.urbanairship.com/api/push/
{
"device_tokens": [
"ABC...",
"FEG..."
],
"schedule_for": [
"2012-07-27 22:48:00",
"2012-07-28 22:48:00"
],
"aps": {
"alert": "Hello from Urban Airship!"
}
}
Python
Example push code
import urbanairship
app_key =
UA_KEYS[group_name]['UA_APPLICATION_KEY']
master_key =
UA_KEYS[group_name]['UA_MASTER_SECRET_KEY']
airship = urbanairship.Airship(app_key,
master_key)
android_json = {'android': {'alert':
'Android push notification text.'}}
airship.broadcast(android_json)
ios_json = {'aps': {'alert':
'iOS push notification text.'}}
airship.broadcast(ios_json)
android_json2 = {'android': {'alert':
'Android push notification text.',
'extra': {'url': 'http://example.com/content'}
}}
airship.broadcast(android_json2)
urbanairship.py
BASE_URL = 'https://go.urbanairship/api'
BROADCAST_URL = BASE_URL + '/push/broadcast/'
def broadcast(self, payload,
exclude_tokens=None):
if exclude_tokens:
payload['exclude_tokens'] = exclude_tokens
body = json.dumps(payload)
status, response = self._request('POST',
body, BROADCAST_URL, 'application/json')
if not status == 200:
raise AirshipFailure(status, response)
Where to go from here
References
-
AT&T network traffic growth:
http://cparente.files.wordpress.com/2012/02/attdatagrowth.jpg
-
Mobile phone in hand:
http://cdn.contentlead.com/wp-content/uploads/2011/12/iPhone-4-in-Hand-e1322839760319.jpg
-
Push notifications counter:
http://www.viberfaq.com/wp-content/uploads/2011/01/apple-push-notification-service.jpg
-
iOS 4 push notification:
http://www.iphoneheat.com/wp-content/uploads/2009/05/push-notifications-iphone-os-30-08.jpg
-
iOS 5 push notifications:
http://www.howfreetips.com/wp-content/uploads/2011/12/push-notifications-ios5-arrange.jpg
-
Android push notifications:
http://urbanairship.com/wp-content/uploads/2011/03/Embedded-Android-Push1.png
-
Fieldrunners:
http://fieldrunners.com/media/
-
Horizontal iPhone:
http://nozbe.net/imgblog/iphone-horizontal.jpeg
-
Horizontal Droid:
http://cdn.androidcentral.com/sites/androidcentral.com/files/articleimage/9274/2010/09/Droid-horizontal.jpg
-
LivingSocial mobile app:
http://a0.ak.lscdn.net/deals/images/iphone_promo/210/screen_2b.jpg