Zend_Mobile_Push_Gcm

Zend_Mobile_Push_Mpns

Zend_Mobile_Push_Mpns provides the ability to send push notifications to Windows Phone. MPNS allows the sending of 3 different types of notifications; which common behavior is in the Zend_Mobile_Push_Message_Mpns base. Followed by specific classes for Raw, Toast and Tile notifications.

Pushing Messages

Note: Prior to pushing messages; you must implement the practices outlined on » Receiving Push Notifications for Windows Phone.

When implementing MPNS; you have several components that you will utilize. Zend_Mobile_Push_Mpns which contains the server components and Zend_Mobile_Push_Message_Mpns_Raw which allows you to send » raw notifications, Zend_Mobile_Push_Message_Mpns_Toast which allows you to send » toast notifications, and Zend_Mobile_Push_Message_Mpns_Tile which allows you to send » tile notifications. 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.

  1. span style="color: #808080; font-style: italic;">// raw notification
  2. 'http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN');
  3. $message->setMessage('<notification><foo id="bar" /></notification>');
  4. $messages[] = $message;
  5.  
  6. // toast message
  7. 'http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN');
  8. $message->setTitle('Foo');
  9. $message->setMessage('Bar');
  10. $messages[] = $message;
  11.  
  12. // tile message
  13. 'http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN''foo.bar''Bar Foo''Remove token: ''Error occurred, token: ' . $m->getToken() . ' - '
Exceptions and Remediation Techniques
Exception Meaning Handling
Zend_Mobile_Push_Exception These types of exceptions are more generic in nature and are thrown either from MPNS or internally on input validation Read the message and determine remediation steps.
Zend_Mobile_Push_Exception_DeviceQuotaExceeded You have sent too many messages to this device; you may retry again later. Try again later or implement » Exponential Backoff .
Zend_Mobile_Push_Exception_InvalidPayload Generally the payload will not throw an exception unless the size of the payload is too large or it is missing required content. Check the size of the payload is within the requirements of MPNS
Zend_Mobile_Push_Exception_InvalidToken Any form of an invalid token will be if the device is no longer subscribed, inactive or not valid. In some cases you may attempt to resend in an hour; this will be stated in the exception. Otherwise you will want to remove the token from being sent to again.
Zend_Mobile_Push_Exception_QuotaExceeded You have reached the per-day throttling. Per-day throttling is only on unauthenticated web services; you will need to » register your application for notifications.

Advanced Messages

MPNS 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_Mpns_* allows you to do far more advanced messaging outlined below.

Tile Messages

Tile messages have additional optional attributes for Windows Phone 7.1+; you must ensure that you are sending to a device with the proper version otherwise your notification will fail.

  1. span style="color: #ff0000;">'http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN'); // REPLACE WITH NOTIFICATION URI FROM MPNS
  2. 'foo.jpg''Bar');
  3.  
  4. // other optional attributes for wp7.1+
  5. $message->setTileId('/Foo.xaml''blue.jpg');
  6. $message->setBackTitle('Bar');
  7. $message->setBackContent('Foo Bar');

Toast Messages

Toast messages have additional optional attributes for Windows Phone 7.1+; you must ensure that you are sending to a device with the proper version otherwise your notification will fail.

  1. span style="color: #ff0000;">'http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN'); // REPLACE WITH NOTIFICATION URI FROM MPNS
  2. $message->setTitle('Foo');
  3. $message->setMessage('Bar');
  4.  
  5. // optional attributes for wp7.1+
  6. $message->setParams('?bar=foo'); //optional parameters

Zend_Mobile_Push_Gcm