leveraging zend framework for sending push notifications
TRANSCRIPT
![Page 1: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/1.jpg)
Leveraging
Zend Framework
Sending Push Notifications By Mike Willbanks
Software Engineering Manager
CaringBridge
MinneBar April 7, 2012
![Page 2: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/2.jpg)
2
•Talk
Slides will be online later!
•Me
Software Engineering Manager at CaringBridge
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: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/3.jpg)
3
•Overview of Push Notifications
•Overview of Zend_Mobile [_Push]
•Android Push Notifications (C2DM)
•Apple Push Notifications (APNS)
•Microsoft Push Notifications
•BlackBerry Push Notifications
•Questions
Although you can bring them up at anytime!
Agenda
![Page 4: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/4.jpg)
Overview What are they?
What is the benefit?
High level; how do these things work?
![Page 5: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/5.jpg)
5
•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.
What Are They
![Page 6: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/6.jpg)
6
In Pictures…
![Page 7: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/7.jpg)
Benefits of Push Notifications The benefits of push notifications are numerous; the
question is if you have an app and you are running services
to poll; why would you do such a thing!
![Page 8: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/8.jpg)
8
One word… Battery Life
![Page 9: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/9.jpg)
9
Impact of Polling
![Page 10: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/10.jpg)
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: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/11.jpg)
11
Can We Deliver?
![Page 12: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/12.jpg)
12
•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.
Delivery
![Page 13: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/13.jpg)
How These Things Work The 10,000 foot view.
![Page 14: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/14.jpg)
14
10,000 Foot View of C2DM
![Page 15: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/15.jpg)
15
10,000 Foot View of APNS
![Page 16: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/16.jpg)
16
10,000 Foot View of Windows Push
![Page 17: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/17.jpg)
17
10,000 Foot View of BlackBerry
![Page 18: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/18.jpg)
18
•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
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/libra
ry/Zend/Mobile/
Overview of Zend_Mobile_Push
![Page 19: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/19.jpg)
19
•svn checkout from ZF OR through github
•Adjust your include_path (likely set in index.php)
•You’re ready to rock!
•Once you upgrade to 1.12 after it is released you won’t
have anything more to do.
Setting up the Library
![Page 20: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/20.jpg)
Walking Through Android Understanding C2DM
Anatomy of a Message
Pushing Messages
Displaying Items on the Client
![Page 21: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/21.jpg)
21
• 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)
Understanding C2DM
![Page 22: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/22.jpg)
22
•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.
Registering for C2DM
![Page 23: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/23.jpg)
23
Anatomy of the Mobile App
![Page 24: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/24.jpg)
24
•We must update the Manifest file to state additional
permissions.
•We will then create a broadcast receiver that will handle
the messages and registration.
How the Application Works
![Page 25: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/25.jpg)
25
Example Manifest
![Page 26: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/26.jpg)
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
![Page 28: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/28.jpg)
28
•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.
Implementing a Server
![Page 29: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/29.jpg)
29
How the Server Works
![Page 30: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/30.jpg)
30
Using Zend_Mobile_Push_C2dm
![Page 31: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/31.jpg)
Apple Push Notifications A brief walk-through on implementing notifications on the
iPhone.
![Page 32: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/32.jpg)
32
• 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.
Understanding APNS
![Page 33: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/33.jpg)
33
•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 34: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/34.jpg)
34
Anatomy of the Application
![Page 35: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/35.jpg)
35
•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 36: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/36.jpg)
36
Example of Handling Registration
![Page 37: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/37.jpg)
37
Example of Handling Remote Notification
![Page 38: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/38.jpg)
38
•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 bytes
Implementing the Server
![Page 39: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/39.jpg)
39
How the Server Works
![Page 40: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/40.jpg)
40
Using Zend_Mobile_Push_Apns
![Page 41: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/41.jpg)
41
Using Zend_Mobile_Push_Apns Feedback
![Page 42: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/42.jpg)
Microsoft Push Notifications Well, I am not certain if they will find the market share yet
but hey; some people need to build apps for it!
![Page 43: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/43.jpg)
43
• 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.aspx
Understanding MPNS
![Page 44: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/44.jpg)
44
•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 45: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/45.jpg)
45
Anatomy of MPNS
![Page 46: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/46.jpg)
46
Registering for Push
![Page 47: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/47.jpg)
47
Implementing the Callbacks for Notifications
![Page 48: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/48.jpg)
48
Using Zend_Mobile_Push_Mpns Raw Messages
![Page 49: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/49.jpg)
49
Using Zend_Mobile_Push_Mpns Toast Messages
![Page 50: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/50.jpg)
50
Using Zend_Mobile_Push_Mpns Tile Messages
![Page 51: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/51.jpg)
BlackBerry Push Notifications Blackberry push notifications are not currently supported…
But we’ll talk about them anyway.
![Page 52: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/52.jpg)
52
• 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 53: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/53.jpg)
53
Anatomy of BB Push
![Page 54: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/54.jpg)
54
•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 55: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/55.jpg)
55
•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 56: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/56.jpg)
56
•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 57: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/57.jpg)
Moving on… The future, resources and the end!
![Page 58: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/58.jpg)
58
•ZF 2
A new version will eventually come that is more inline with where
Zend Framework 2 is going. However, there are bigger fish to fry
at this point.
•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 59: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/59.jpg)
59
• 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
• 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
Resources
![Page 60: Leveraging Zend Framework for Sending Push Notifications](https://reader033.vdocument.in/reader033/viewer/2022052822/554fa11ab4c90586258b49a3/html5/thumbnails/60.jpg)
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