Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Zend Framework Push Notifications

9 024 vues

Publié le

Presentation on sending push notifications with Zend Framework based on work to create Zend_Mobile_Push. Currently handles APNs (iPhone/iPad/iTouch), C2DM (Android) and MPNS (Windows Mobile). Additionally mentions of sending push notifications with WAP PAP (BlackBerry).

Publié dans : Technologie
  • Identifiez-vous pour voir les commentaires

Zend Framework Push Notifications

  1. 1. MNPHP January 5, 2012ZF: Push Notifications By Mike Willbanks Software Engineering Manager CaringBridge
  2. 2. About Mike… • Software Engineering Manager at CaringBridge • Open Source Contributor • Where you can find me:  Twitter: mwillbanks  G+: Mike Willbanks  IRC (freenode): lubs  Blog: http://blog.digitalstruct.com2
  3. 3. Agenda • Overview of Push Notifications • Overview of Zend_Mobile [_Push]  Not currently implemented in ZF 1.x; maybe ZF 1.12. • Android Push Notifications (C2DM) • Apple Push Notifications (APNS) • Microsoft Push Notifications • BlackBerry Push Notifications • Questions  Although you can bring them up at anytime!3
  4. 4. OverviewWhat are they?What is the benefit?High level; how do these things work?
  5. 5. What Are They • Push Notifications…  Are a message pushed to a central location and delivered to you.  Are (often) the same thing at a pub/sub model.  In the Mobile Space… • These messages often contain other technologies such as alerts, tiles, or raw data.5
  6. 6. In Pictures…6
  7. 7. Benefits of Push NotificationsThe benefits of push notifications are numerous; thequestion is if you have an app and you are running servicesto poll; why would you do such a thing!
  8. 8. One word… Battery Life8
  9. 9. Impact of Polling9
  10. 10. Battery Life • 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.10
  11. 11. Can We Deliver?11
  12. 12. Delivery • When you poll; things are generally 15+ minutes out to save on battery. In a push notification these happen almost instantly.  We’ve generally seen within 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.12
  13. 13. How These Things WorkThe 10,000 foot view.
  14. 14. 10,000 Foot View of C2DM14
  15. 15. 10,000 Foot View of APNS15
  16. 16. 10,000 Foot View of Windows Push16
  17. 17. 10,000 Foot View of BlackBerry17
  18. 18. Overview of Zend_Mobile_Push • Created Zend_Mobile component in November because I was irritated with the other libraries that currently existed. • More fluid way of sending push notifications. • Requires Zend Framework 1.x  Hopefully will make it into the ZF 1.12 release planned within the next month or two. • Handles sending push notifications to 3 systems  APNS, C2DM and MPNS • Library is located in my GitHub account  https://github.com/mwillbanks/Zend_Mobile18
  19. 19. Setting up the Library • Git clone the package somewhere you would like it to live. • Adjust your include_path (likely set in index.php) • You’re ready to rock! • Hopefully; in the future you won’t have to do anything 19
  20. 20. Walking Through AndroidUnderstanding C2DMAnatomy of a MessagePushing MessagesDisplaying Items on the Client
  21. 21. Understanding C2DM • It allows third-party application servers to send lightweight messages to their Android applications. • C2DM makes no guarantees about delivery or the order of messages. • An application on an Android device doesn’t need to be running to receive messages. • It does not provide any built-in user interface or other handling for message data. • It requires devices running Android 2.2 or higher that also have the Market application installed. • It uses an existing connection for Google services (Through the Google Market)21
  22. 22. Registering for C2DM • First things first – you must sign up to actually utilize C2DM  http://code.google.com/android/c2dm/signup.html  C2DM only works on Android w/ Google Market • Basically excludes: Amazon Kindle Fire.22
  23. 23. Anatomy of the Mobile App23
  24. 24. How the Application Works • We must update the Manifest file to state additional permissions. • We will then create a broadcast receiver that will handle the messages and registration.24
  25. 25. Example Manifest25
  26. 26. Handling the Registration (or Unregistering) • Registration / Registration Updates and Unregistering. • Registration is generally on app start up. • Be nice and allow your users to unregister from the push notification service 26
  27. 27. Example Receiver More at: http://bit.ly/bxOoMO towards end of article.27
  28. 28. Implementing a Server • Some limitations  200K messages per day by default; use them wisely however you may request more.  1K message payload maximum.  You must implement incremental back off.28
  29. 29. How the Server Works29
  30. 30. Using Zend_Mobile_Push_C2dm30
  31. 31. Apple Push NotificationsA brief walk-through on implementing notifications on theiPhone.
  32. 32. Understanding APNS • The maximum size allowed for a notification payload is 256 bytes. • It allows third-party application servers to send lightweight messages to their iPhone/iPad applications. • Apple makes no guarantees about delivery or the order of messages. • An application on an iPhone/iPad device doesn’t 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.32
  33. 33. Preparing to Implement Apple Push Notifications • 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.33
  34. 34. Anatomy of the Application34
  35. 35. How the Application Works • 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.35
  36. 36. Example of Handling Registration36
  37. 37. Example of Handling Remote Notification37
  38. 38. Implementing the Server • Some Limitations  Don’t send too many through at a time; meaning around 100K  • Every once in a while use a usleep  Max payload is 256 bytes38
  39. 39. How the Server Works39
  40. 40. Using Zend_Mobile_Push_Apns40
  41. 41. Using Zend_Mobile_Push_Apns Feedback41
  42. 42. Microsoft Push NotificationsWell, I am not certain if they will find the market share yetbut hey; some people need to build apps for it!
  43. 43. Understanding MPNS • It allows third-party application servers to send lightweight messages to their Windows Mobile applications. • Microsoft makes no guarantees about delivery or the order of messages. (See a pattern yet?) • 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.aspx43
  44. 44. Preparing to Implement MPNS • 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 certificates Subject value.  Install the TLS certificate on your web service and enable HTTP client authentication.44
  45. 45. Anatomy of MPNS45
  46. 46. Registering for Push46
  47. 47. Implementing the Callbacks for Notifications47
  48. 48. Using Zend_Mobile_Push_Mpns Raw Messages48
  49. 49. Using Zend_Mobile_Push_Mpns Toast Messages49
  50. 50. Using Zend_Mobile_Push_Mpns Tile Messages50
  51. 51. BlackBerry Push NotificationsAre these even going to be needed in another year?I keep thinking about adding them in; but I am completelyunsure if they work…
  52. 52. Understanding BlackBerry Push • 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…52
  53. 53. Anatomy of BB Push53
  54. 54. Application Code • 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-  Since I do not touch blackberry; or have the desire, I would ensure the library works for people that want it; just help me test it!54
  55. 55. Preparing to Implement • 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:  Updated to be OO; non-tested and a bit sloppy: https://github.com/mwillbanks/BlackBerryPush  Original source: http://bit.ly/nfbHXp55
  56. 56. Implementing BB Push w/ PHP • Be aware… this code is highly alpha – never been tested. • If you do use BlackBerry push messages; please connect with me so that I can include this in the Zend_Mobile_Push component.56
  57. 57. Moving on…The future, resources and the end!
  58. 58. Next steps • ZF 2  If / when this library makes it into ZF 1.x; I will be working on it for 2.x. My first focus is ensuring it’s successful addition to ZF 1.x. I have some code for the 2.x version but some minor refactoring is due to fit the new model. • BlackBerry  Who knows where they will end up. All I know is that developing for it seems painful and the documentation is certainly not what I would like to see.  There is a large need for a quality implementation but at the same point developers are not highly interested in their platform.58
  59. 59. Resources • Main Sites  Apple Push Notifications: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Con ceptual/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  BlackBerry: https://github.com/mwillbanks/BlackBerryPush • Might be broken but at least better than what I found anywhere else 59
  60. 60. Questions?These slides will be posted to SlideShare after the meetup. Slideshare: http://www.slideshare.net/mwillbanks Twitter: mwillbanks G+: Mike Willbanks IRC (freenode): lubs Blog: http://blog.digitalstruct.com