Author: | Adam Lowry, Urban Airship |
---|---|
Date: | August 1st, 2009 |
What, Why, and How
We'll focus on How
- Push notifications are the only way to interact with an application if it isn't running.
- Alerts, badge updates, sounds (plus custom payload)
- Lots of potential, lots of limitations
- Engagement
- Server-initiated updates
- RSS, IM, news
<key>aps-environment</key>
<string>development</string>
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
- (void)application:
(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:
(NSData *)deviceToken {
[deviceToken description]
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:
(NSError *) error
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"remote notification: %@",[userInfo description]);
}
This started as JSON, but it's already been translated to NSDictionary, NSArray, and NSString objects
Privacy Enhanced Mail format is generally most useful
openssl pkcs12 -in cred.p12 -out certkey.pem -nodes -clcerts
direct_socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
direct_socket.setsockopt(socket.SOL_SOCKET,
socket.SO_KEEPALIVE, 1)
socket = ssl.wrap_socket(direct_socket,
certfile='/path/to/pem')
socket.connect(
('gateway.sandbox.push.apple.com', 2195))
From Apple Documentation - their diagram, not mine
payload = json.dumps({'aps': {'alert': 'Hello!'}})
hex_token = token.decode('hex')
format = '!BH32sH%ds' % len(payload)
notification = struct.pack(format, 0, 32, hex_token,
len(payload), payload)
socket.write(notification)
- Device is on
- Device has at least one application with push enabled
- Device has removed your application or turned off push
From Apple Documentation - their diagram, not mine
feedback_format = "!iH32s"
data = socket.recv(
struct.calcsize(feedback_format))
timestamp, _, device_token = \
struct.unpack(feedback_format, data)
device_token = binascii.hexlify(device_token)
- Device only displays last alert
- No feedback on delivery success unless an alert is viewed
- Lack of debugging tools
- No warnings on downtime!
- No logging
- Maintaining connections, handling connection errors
- Storing details on tokens, validity
- Scaling to multiple connections