push to me: mobile push notifications (zend framework)

61
Push to Me! Mobile Push Notifications By Mike Willbanks Sr. Web Architect Manager Barnes and Noble ThatConference August 14 th 2012

Upload: mike-willbanks

Post on 11-May-2015

5.786 views

Category:

Technology


2 download

DESCRIPTION

Implementation of Push notifications for the various providers. Google GCM, Apple APNS, Microsoft MPNS and a little detail on Blackberry.

TRANSCRIPT

Page 1: Push to Me: Mobile Push Notifications (Zend Framework)

Push to Me! Mobile Push Notifications

By Mike Willbanks

Sr. Web Architect Manager

Barnes and Noble

ThatConference August 14th 2012

Page 2: Push to Me: Mobile Push Notifications (Zend Framework)

2

• Talk

 Slides will be online later!

• Me

 Sr. Web Architect Manager at Barnes and Noble

 Prior MNPHP Organizer

 Open Source Contributor (Zend Framework and various others)

 Where you can find me:

• Twitter: mwillbanks G+: Mike Willbanks

•  IRC (freenode): mwillbanks Blog: http://blog.digitalstruct.com

• GitHub: https://github.com/mwillbanks

Housekeeping…

Page 3: Push to Me: Mobile Push Notifications (Zend Framework)

3

• Overview of Push Notifications

• Android Push Notifications (C2DM)

• Apple Push Notifications (APNS)

• Microsoft Push Notifications

• BlackBerry Push Notifications

• Questions

Agenda

Page 4: Push to Me: Mobile Push Notifications (Zend Framework)

Overview What are they?

What is the benefit?

High level; how do these things work?

Page 5: Push to Me: Mobile Push Notifications (Zend Framework)

5

• Push Notifications…

 Are a message pushed to a central location and delivered to you.

 Are (often) the same thing as a pub/sub model.

 In the Mobile Space…

• These messages often contain other technologies such as alerts, tiles, or raw data.

What Are They

Page 6: Push to Me: Mobile Push Notifications (Zend Framework)

6

In Pictures…

Page 7: Push to Me: Mobile Push Notifications (Zend Framework)

Benefits of Push Notifications Battery Life

Delivery

Page 8: Push to Me: Mobile Push Notifications (Zend Framework)

8

One word… Battery Life

Page 9: Push to Me: Mobile Push Notifications (Zend Framework)

9

Impact of Polling

Page 10: Push to Me: Mobile Push Notifications (Zend Framework)

10

• Push notification services for mobile are highly efficient; it runs in the device background and enables your application to receive the message.

• The other part of this; if you implemented it otherwise you would be polling. This not only wastes precious battery but also wastes their bandwidth.

 NOTE: This is not always true; if you are sending data to the phone more often than a poll would do in 15 minutes; you are better off implementing polling.

Battery Life

Page 11: Push to Me: Mobile Push Notifications (Zend Framework)

11

Can We Deliver?

Page 12: Push to Me: Mobile Push Notifications (Zend Framework)

12

• When you poll; things are generally 15+ minutes out to save on battery. In a push notification these happen almost instantly.

 In practice have seen 1-3s between sending a push notification to seeing it arrive on the device.

• Additionally; push notifications can be sent to the device even if it is offline or turned off.

• However, not all messages are guaranteed for delivery

 You may hit quotas

 Some notification servers only allow a single message to be in queue at 1 time (some group by collapse key), and others remove duplicates.

Delivery

Page 13: Push to Me: Mobile Push Notifications (Zend Framework)

How These Things Work The 10,000 foot view.

Page 14: Push to Me: Mobile Push Notifications (Zend Framework)

14

10,000 Foot View of GCM

RegistrationRequest

Registration ID

Store IDSend Messages

Push Messages

Page 15: Push to Me: Mobile Push Notifications (Zend Framework)

15

10,000 Foot View of APNS

Page 16: Push to Me: Mobile Push Notifications (Zend Framework)

16

10,000 Foot View of Windows Push

Page 17: Push to Me: Mobile Push Notifications (Zend Framework)

17

10,000 Foot View of BlackBerry

Page 18: Push to Me: Mobile Push Notifications (Zend Framework)

18

• Created Zend_Mobile component

 Consistency, Quality, Ease of Use

• Requires Zend Framework 1.x

 Committed in the ZF trunk; waiting for 1.12 release.

• Handles sending push notifications to 3 systems

 APNS, C2DM and MPNS

• Library is located in my GitHub account & ZF Trunk

 https://github.com/mwillbanks/Zend_Mobile

 http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mobile/

Overview of Zend_Mobile_Push

Page 19: Push to Me: Mobile Push Notifications (Zend Framework)

19

• Manual Setup (Current Method)

 svn checkout from ZF OR through github

 Adjust your include_path (likely set in index.php)

• ZF 1.12

 Once released; no manual setup necessary.

Setting up the Library

Page 20: Push to Me: Mobile Push Notifications (Zend Framework)

Walking Through Android Understanding GCM

Anatomy of a Message

Pushing Messages

Displaying Items on the Client

Page 21: Push to Me: Mobile Push Notifications (Zend Framework)

21

• Allows application servers to send their app messages.

• Is no guarantee for delivery or the order of messages.

• Application does not need to be running to receive messages.

• It does not provide any built-in user interface or other handling for message data.

• Requires Android 2.2 with Google Play store installed.

• It uses an existing connection for Google services

 Pre 3.0 devices requires a Google Account to be setup.

 4.0.4 or higher does not.

Understanding GCM

Page 22: Push to Me: Mobile Push Notifications (Zend Framework)

22

• Sign in to the Google API’s console page

 https://code.google.com/apis/console

 Create a Project – keep note of the project #

 Select Services

 Turn on Google Cloud Messaging

 Accept terms of use

 Create an API key

Registering for GCM

Page 23: Push to Me: Mobile Push Notifications (Zend Framework)

23

Anatomy of the Mobile App

Your ApplicationGoogleCloud

MessagingYour Web Service

Register

Registration ID

Save Registration ID

Page 24: Push to Me: Mobile Push Notifications (Zend Framework)

24

• Import the GCM libraries

 /path/to/sdk-dir/extras/google/gcm-client/dist/gcm.jar

• Update AndroidManifest.xml

 We need certain permissions for GCM to run.

• Create GCMIntentService

 Receives the GCM messages from the GCMBroadcastReceiver

How the Application Works

Page 25: Push to Me: Mobile Push Notifications (Zend Framework)

25

Example Manifest

Page 26: Push to Me: Mobile Push Notifications (Zend Framework)

26

Handling the Registration (or Unregistering)

Page 27: Push to Me: Mobile Push Notifications (Zend Framework)

27

Example Intent Service

Page 28: Push to Me: Mobile Push Notifications (Zend Framework)

28

Renders something like…

Page 29: Push to Me: Mobile Push Notifications (Zend Framework)

29

• Some limitations

 No Quota!

 4KB payload maximum

 You must implement incremental back off.

• Old Limitations of C2DM

 200K messages per day by default; use them wisely however you may request more.

 1K message payload maximum.

Implementing a Server

Page 30: Push to Me: Mobile Push Notifications (Zend Framework)

30

How the Server Works

Your ApplicationGoogleCloud

Messaging

Your Web Application

Message withRegistration IDs

Message sent to Application

RequiresProject # and API

token

Device must

be onlineQueues till

sent or expires

Page 31: Push to Me: Mobile Push Notifications (Zend Framework)

31

Using Zend_Mobile_Push_Gcm

Page 32: Push to Me: Mobile Push Notifications (Zend Framework)

Apple Push Notifications A brief walk-through on implementing notifications on the iPhone.

Page 33: Push to Me: Mobile Push Notifications (Zend Framework)

33

•  The maximum size allowed for a notification payload is 256 bytes.

• Allows application servers to send their app messages.

• No guarantees about delivery or the order of messages.

• Application does not need to be running to receive messages.

• Message adheres to strict JSON but is abstracted away for us in how we will be using it today.

• Messages should be sent in batches.

• A feedback service must be listened to.

Understanding APNS

Page 34: Push to Me: Mobile Push Notifications (Zend Framework)

34

• You must create a SSL certificate and key from the provisioning portal

• After this is completed the provisioning profile will need to be utilized for the application.

• Lastly, you will need to install the certificate and key on the server.

 In this case; you will be making a pem certificate.

Preparing to Implement Apple Push Notifications

Page 35: Push to Me: Mobile Push Notifications (Zend Framework)

35

Anatomy of the Application

Page 36: Push to Me: Mobile Push Notifications (Zend Framework)

36

• Registration

 The application calls the registerForRemoteNotificationTypes: method.

 The delegate implements the application:didRegisterForRemoteNotificationsWithDeviceToken: method to receive the device token.

 It passes the device token to its provider as a non-object, binary value.

• Notification

 By default this just works based on the payload; for syncing you would implement this on the launch.

How the Application Works

Page 37: Push to Me: Mobile Push Notifications (Zend Framework)

37

Example of Handling Registration

Page 38: Push to Me: Mobile Push Notifications (Zend Framework)

38

Example of Handling Remote Notification

Page 39: Push to Me: Mobile Push Notifications (Zend Framework)

39

• Some Limitations

 Don’t send too many through at a time; meaning around 100K J

• Every once in a while use a usleep

 Max payload is 256 bytes

Implementing the Server

Page 40: Push to Me: Mobile Push Notifications (Zend Framework)

40

How the Server Works

Page 41: Push to Me: Mobile Push Notifications (Zend Framework)

41

Using Zend_Mobile_Push_Apns

Page 42: Push to Me: Mobile Push Notifications (Zend Framework)

42

Using Zend_Mobile_Push_Apns Feedback

Page 43: Push to Me: Mobile Push Notifications (Zend Framework)

Microsoft Push Notifications Windows Mobile has really usable push notifications!

Page 44: Push to Me: Mobile Push Notifications (Zend Framework)

44

• Allows application servers to send their app messages.

• No guarantee about delivery or the order of messages.

• 3 types of messages: Tile, Toast or Raw

• Limitations:

 One push channel per app, 30 push channels per device, additional adherence in order to send messages

 3K Payload, 1K Header

• http://msdn.microsoft.com/en-us/library/ff402537.aspx

Understanding MPNS

Page 45: Push to Me: Mobile Push Notifications (Zend Framework)

45

• Upload a TLS certificate to Windows Marketplace

 The Key-Usage value of the TLS certificate must be set to include client authentication.

 The Root Certificate Authority (CA) of the certificate must be one of the CAs listed at: SSL Root Certificates for Windows Phone.

 Stays authenticated for 4 months.

 Set Service Name to the Common Name (CN) found in the certificate's Subject value.

 Install the TLS certificate on your web service and enable HTTP client authentication.

Preparing to Implement MPNS

Page 46: Push to Me: Mobile Push Notifications (Zend Framework)

46

Anatomy of MPNS

Page 47: Push to Me: Mobile Push Notifications (Zend Framework)

47

Registering for Push

Page 48: Push to Me: Mobile Push Notifications (Zend Framework)

48

Implementing the Callbacks for Notifications

Page 49: Push to Me: Mobile Push Notifications (Zend Framework)

49

Using Zend_Mobile_Push_Mpns Raw Messages

Page 50: Push to Me: Mobile Push Notifications (Zend Framework)

50

Using Zend_Mobile_Push_Mpns Toast Messages

Page 51: Push to Me: Mobile Push Notifications (Zend Framework)

51

Using Zend_Mobile_Push_Mpns Tile Messages

Page 52: Push to Me: Mobile Push Notifications (Zend Framework)

BlackBerry Push Notifications Blackberry push notifications are not currently supported…

But we’ll talk about them anyway.

Page 53: Push to Me: Mobile Push Notifications (Zend Framework)

53

• It allows third-party application servers to send lightweight messages to their BlackBerry applications.

• Allows a whopping 8K or the payload

• Uses WAP PAP 2.2 as the protocol

• Mileage may vary…

Understanding BlackBerry Push

Page 54: Push to Me: Mobile Push Notifications (Zend Framework)

54

Anatomy of BB Push

Page 55: Push to Me: Mobile Push Notifications (Zend Framework)

55

• They have a “Sample” but it is deep within their Push SDK. Many of which are pre-compiled.

 Documentation is hard to follow and the sample isn’t exactly straight forward:

•  Install the SDK then go to BPSS/pushsdk-low-level/sample-push-enabled-app/ and unzip sample-push-enabled-app-1.1.0.16-sources.jar

 Completely uncertain on how to make it all work…

Application Code

Page 56: Push to Me: Mobile Push Notifications (Zend Framework)

56

• You need to register with BlackBerry and have all of the application details ready to go:

 https://www.blackberry.com/profile/?eventId=8121

• Download the PHP library:

 NOTE: I am not certain if any of these actually work…

 Updated to be OO; non-tested and a bit sloppy: https://github.com/mwillbanks/BlackBerryPush

 Original source: http://bit.ly/nfbHXp

Preparing to Implement

Page 57: Push to Me: Mobile Push Notifications (Zend Framework)

57

• Again, never tested nor do I know if it works.

• If you do use BlackBerry push messages; please connect with me

 I would like to allow us to get these into the component.

Implementing BB Push w/ PHP

Page 58: Push to Me: Mobile Push Notifications (Zend Framework)

Moving on… The future, resources and the end!

Page 59: Push to Me: Mobile Push Notifications (Zend Framework)

59

• ZF 2

 Working on Service Modules that will implement underlying functionality soon.

• Hopefully by October?

• BlackBerry

 There is a need for a quality implementation in PHP but RIM’s documentation and how they work with developers makes this increasingly difficult.

• Register, Forums and bad documentation… all for?

Next steps

Page 60: Push to Me: Mobile Push Notifications (Zend Framework)

60

•  Main Sites

  Apple Push Notifications: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

  Google C2DM (Android): http://code.google.com/android/c2dm/

  Microsoft Push Notifications: http://msdn.microsoft.com/en-us/library/ff402558(v=vs.92).aspx

  BlackBerry Push Notifications: http://us.blackberry.com/developers/platform/pushapi.jsp

•  Push Clients:

  Zend_Mobile:

•  https://github.com/mwillbanks/Zend_Mobile

•  http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mobile/

  BlackBerry: https://github.com/mwillbanks/BlackBerryPush

•  Might be broken but at least better than what I found anywhere else J

Resources

Page 61: Push to Me: Mobile Push Notifications (Zend Framework)

Questions? These slides will be posted to SlideShare & SpeakerDeck.

 Slideshare: http://www.slideshare.net/mwillbanks

 SpeakerDeck: http://speakerdeck.com/u/mwillbanks

 Twitter: mwillbanks

 G+: Mike Willbanks

 IRC (freenode): mwillbanks

 Blog: http://blog.digitalstruct.com

 GitHub: https://github.com/mwillbanks