Slide 1

Slide 1 text

IOS PUSH NOTIFICATIONS ZERO TO ENGAGEMENT Created by Adam Duke    @adamvduke @adamvduke http://adamvduke.com

Slide 2

Slide 2 text

ABOUT ME Adam Duke Engineer/Co-Founder at Symmetric Infinity http://symmetricinfinity.com Working with iOS for about 4 years Working with Ruby/Rails for about 3 years I ❤ open source

Slide 3

Slide 3 text

AGENDA What is a push notification? How do they work? Communicating with APNS Prerequisites for communicating Code Walkthrough Pitfalls Feedback Upcoming Changes/Features Third-party Providers

Slide 4

Slide 4 text

WHAT IS A PUSH NOTIFICATION? Most of the time they look something like...

Slide 5

Slide 5 text

HOW DO THEY WORK? 1. Apple maintains a persistent connection to each device 2. Something happens that you want to tell a user about 3. Package up some data in Apple's proprietary protocol 4. Send the data to Apple 5. Apple forwards the information to your user's device

Slide 6

Slide 6 text

TL;DR

Slide 7

Slide 7 text

PROPRIETARY PROTOCOL? Uses a plain TCP socket secured by SSL A single notification looks like... Ewww Ain't nobody got time for that Most platforms have a library for this

Slide 8

Slide 8 text

PREREQUISITES TO SEND A NOTIFICATION 1. Certificates to secure your socket These are tied to a specific bundle id e.g. com.apple.itunes.iphone Configure/Download from developer.apple.com 2. A device token Who do you want to send a notification to? We'll talk about how to get this in a minute. 3. A JSON hash of the data you'd like to send The "alert" key will be the text shown The "badge" key will set the badge on the icon The "sound" key identifies the sound to play https://zeropush.com/documentation/generating_certificates

Slide 9

Slide 9 text

WHAT DO THEY LOOK LIKE? CERTIFICATES This is just a public/private key pair

Slide 10

Slide 10 text

WHAT DO THEY LOOK LIKE? DEVICE TOKEN 3 9 9 a a c 7 0 e 1 9 1 9 4 3 1 5 3 a 5 c 9 c 2 9 1 f d 7 5 f d a 3 6 9 c 3 c 6 d 5 c 7 c 3 e b 7 7 a 8 c 2 a e 6 0 1 b d 6 c 4

Slide 11

Slide 11 text

WHAT DO THEY LOOK LIKE? NOTIFICATION PAYLOAD { " a p s " : { " a l e r t " : " Y o u ' v e g o t m a i l ! " , " b a d g e " : 9 , " s o u n d " : " s p e c i a l _ e d _ m a i l . a i f f " } } { " a p s " : { " a l e r t " : " A d a m D . s e n t y o u a m e s s a g e ! " , " b a d g e " : 9 , " s o u n d " : " b i n g b o n g . a i f f " } , " i n f o " : { " t y p e " : " c h a t " , " u s e r _ i d " : " 1 2 3 4 5 6 " } }

Slide 12

Slide 12 text

HOW DO I GET A DEVICE TOKEN? Write some code! - ( v o i d ) a p p l i c a t i o n D i d B e c o m e A c t i v e : ( U I A p p l i c a t i o n * ) a p p l i c a t i o n { / * E v e r y t i m e t h e a p p b e c o m e s a c t i v e , a t t e m p t t o r e g i s t e r * / [ a p p l i c a t i o n r e g i s t e r F o r R e m o t e N o t i f i c a t i o n T y p e s : ( U I R e m o t e N o t i f i c a t i o n T y p e B a d g e | U I R e m o t e N o t i f i c a t i o n T y p e S o u n d | U I R e m o t e N o t i f i c a t i o n T y p e A l e r t ) ] ; }

Slide 13

Slide 13 text

HOW DO I GET A DEVICE TOKEN? Remember this is Objective-C, so... Write a little more code! - ( v o i d ) a p p l i c a t i o n : ( U I A p p l i c a t i o n * ) a p p l i c a t i o n d i d R e g i s t e r F o r R e m o t e N o t i f i c a t i o n s W i t h D e v i c e T o k e n : ( N S D a t a * ) d e v i c e T o k e n { / * T u r n t h e d a t a i n t o a s t r i n g . S o m e o n e w i l l t e l l m e I c a n d o t h i s w i t h a r e g e x * / N S S t r i n g * t o k e n = [ d e v i c e T o k e n d e s c r i p t i o n ] ; t o k e n = [ t o k e n s t r i n g B y R e p l a c i n g O c c u r r e n c e s O f S t r i n g : @ " < " w i t h S t r i n g : @ " " ] ; t o k e n = [ t o k e n s t r i n g B y R e p l a c i n g O c c u r r e n c e s O f S t r i n g : @ " > " w i t h S t r i n g : @ " " ] ; t o k e n = [ t o k e n s t r i n g B y R e p l a c i n g O c c u r r e n c e s O f S t r i n g : @ " " w i t h S t r i n g : @ " " ] ; / * T O D O : S a v e t h e s t r i n g a l o n g w i t h a u s e r i d t o t h e s e r v e r s o w e c a n k n o w w h i c h d e v i c e s b e l o n g t o w h o m . * / }

Slide 14

Slide 14 text

DEMO The code is available on github https://github.com/adamvduke/ZeroToEngagement

Slide 15

Slide 15 text

PITFALLS Apple expects you to maintain a persistent connection to the APN service Rapid connect/disconnect behavior may be seen as a DOS attack and get you black listed The communication over the connection is asynchronous If there is a problem with a notification Apple will reply, and close the connection Any notifications sent between the error and the reply must be sent again Connections that are idle for too long are closed with no warning

Slide 16

Slide 16 text

FEEDBACK SERVICE 1. User deletes your app 2. You attempt to notify them 3. Apple realizes the app is no longer on their device 4. Apple marks that device as inactive 5. Query the feedback service 6. You mark the device inactive 7. Don't send notifications to inactive devices 8. If the device registers for notifications again, mark the device as active 9. Resume sending notifications

Slide 17

Slide 17 text

UPCOMING CHANGES/FEATURES Silent Notifications Notifications for Websites

Slide 18

Slide 18 text

THIRD-PARTY PROVIDERS 1. - A developer focused push notification provider Full disclosure, my business partner and I wrote this We're looking for beta testers!! 2. - A marketing focused push notification provider 3. - Cloud database and push notification provider Owned by Facebook, possibly subject to NSA Prism data collection 4. ZeroPush.com UrbanAirship.com Parse.com Push.IO

Slide 19

Slide 19 text

QUESTIONS?

Slide 20

Slide 20 text

No content