Zend_Mobile_Push_GcmZend_Mobile_Push_Gcm provides the ability to send push notifications to Android devices that contain Google Services. A message will always be constructed with Zend_Mobile_Push_Message_Gcm. Pushing Messages
When implementing GCM; you have a few components that you will utilize. Zend_Mobile_Push_Gcm which contains the server components, Zend_Mobile_Push_Message_Gcm which contains the message that you would like to send, and Zend_Mobile_Push_Response_Gcm which contains the response from GCM. Each message sent must do an HTTP request; so remember this when sending in large batches. The actual implementation of the code is fairly minimal; however, considerations to error handling must be taken.
Advanced MessagesGCM provides the ability for sending more advanced messages; for instance the examples above show the most basic implementation of a message. Zend_Mobile_Push_Message_Gcm allows you to do far more advanced messaging outlined below. Delay While IdleIf included, indicates that the message should not be sent immediately if the device is idle. The server will wait for the device to become active, and then only the last message for each collapse_key value will be sent. Time to LiveYou may set the time to live in seconds, by default GCM will save it for 4 weeks. Additionally if you specify a Time to Live, you must also set an ID (the collapse key). Generally it is best by using the message data so that you know it is a unique message.
ResponseGCM gives a response back that contains detail that needs to be understood. Most of the time you can just send a message but the server may come back telling you any the message id, any errors and potentially new registration ids. ResultsThe results are most commonly retrieved by calling the getResults() method. However, you may prefer to just get certain results by using the getResult() method. The getResult method utilizes the constants RESULT_* correlating to message id, error or registration id. Several utility methods exist to give you a better idea of what happened during your send. Methods getSuccessCount(), getFailureCount() and getCanonicalCount() let you know how many where successful, how many failures and how many updates to registration ids you have.
|