Zend_Mobile_Push-Mpns.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.mobile.push.mpns">
  4. <title>Zend_Mobile_Push_Mpns</title>
  5. <para>
  6. <classname>Zend_Mobile_Push_Mpns</classname> provides the ability to
  7. send push notifications to Windows Phone. MPNS allows the sending of
  8. 3 different types of notifications; which common behavior is in the
  9. <classname>Zend_Mobile_Push_Message_Mpns</classname> base. Followed by
  10. specific classes for Raw, Toast and Tile notifications.
  11. </para>
  12. <sect2 id="zend.mobile.push.mpns.server">
  13. <title>Pushing Messages</title>
  14. <note>
  15. <para>Prior to pushing messages; you must implement the practices
  16. outlined on <ulink
  17. url="http://msdn.microsoft.com/en-us/library/hh202940(v=VS.92).aspx">Receiving
  18. Push Notifications for Windows Phone</ulink>.
  19. </para>
  20. </note>
  21. <para>
  22. When implementing MPNS; you have several components that
  23. you will utilize. <classname>Zend_Mobile_Push_Mpns</classname>
  24. which contains the server components and
  25. <classname>Zend_Mobile_Push_Message_Mpns_Raw</classname> which
  26. allows you to send <ulink
  27. url="http://msdn.microsoft.com/en-us/library/hh202977(v=VS.92).aspx">raw
  28. notifications</ulink>,
  29. <classname>Zend_Mobile_Push_Message_Mpns_Toast</classname> which
  30. allows you to send <ulink
  31. url="http://msdn.microsoft.com/en-us/library/hh202967(v=VS.92).aspx">toast
  32. notifications</ulink>, and
  33. <classname>Zend_Mobile_Push_Message_Mpns_Tile</classname> which
  34. allows you to send <ulink
  35. url="http://msdn.microsoft.com/en-us/library/hh202970(v=VS.92).aspx">tile
  36. notifications</ulink>. Each message sent must do an HTTP request;
  37. so remember this when sending in large batches.
  38. </para>
  39. <para>
  40. The actual implementation of the code is fairly minimal; however,
  41. considerations to error handling must be taken.
  42. </para>
  43. <programlisting language="php"><![CDATA[
  44. $mpns = new Zend_Mobile_Push_Mpns();
  45. $messages = array();
  46. // raw notification
  47. $message = new Zend_Mobile_Push_Message_Mpns_Raw();
  48. $message->setToken('http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN');
  49. $message->setMessage('<notification><foo id="bar" /></notification>');
  50. $messages[] = $message;
  51. // toast message
  52. $message = new Zend_Mobile_Push_Message_Mpns_Toast();
  53. $message->setToken('http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN');
  54. $message->setTitle('Foo');
  55. $message->setMessage('Bar');
  56. $messages[] = $message;
  57. // tile message
  58. $message = new Zend_Mobile_Push_Mpns_Tile();
  59. $message->setToken('http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN');
  60. $message->setBackgroundImage('foo.bar');
  61. $message->setCount(1);
  62. $message->setTitle('Bar Foo');
  63. $messages[] = $message;
  64. foreach ($messages as $m) {
  65. try {
  66. $mpns->send($m);
  67. } catch (Zend_Mobile_Push_Exception_InvalidToken $e) {
  68. echo 'Remove token: ' . $m->getToken() . PHP_EOL;
  69. } catch (Zend_Mobile_Push_Exception $e) {
  70. echo 'Error occurred, token: ' . $m->getToken() . ' - ' . $e->getMessage() . PHP_EOL;
  71. }
  72. }
  73. ]]></programlisting>
  74. <table id="zend.mobile.push.mpns.server.exceptions">
  75. <title>Exceptions and Remediation Techniques</title>
  76. <tgroup cols="3" align="left" colsep="1" rowsep="1">
  77. <thead>
  78. <row>
  79. <entry>Exception</entry>
  80. <entry>Meaning</entry>
  81. <entry>Handling</entry>
  82. </row>
  83. </thead>
  84. <tbody>
  85. <row>
  86. <entry>Zend_Mobile_Push_Exception</entry>
  87. <entry>These types of exceptions are more generic in nature
  88. and are thrown either from MPNS or internally on input
  89. validation</entry>
  90. <entry>Read the message and determine remediation steps.</entry>
  91. </row>
  92. <row>
  93. <entry>Zend_Mobile_Push_Exception_DeviceQuotaExceeded</entry>
  94. <entry>You have sent too many messages to this device;
  95. you may retry again later.</entry>
  96. <entry>Try again later or implement <ulink
  97. url="http://en.wikipedia.org/wiki/Exponential_backoff">
  98. Exponential Backoff
  99. </ulink>.</entry>
  100. </row>
  101. <row>
  102. <entry>Zend_Mobile_Push_Exception_InvalidPayload</entry>
  103. <entry>Generally the payload will not throw an exception
  104. unless the size of the payload is too large or it is missing
  105. required content.</entry>
  106. <entry>Check the size of the payload is within the
  107. requirements of MPNS</entry>
  108. </row>
  109. <row>
  110. <entry>Zend_Mobile_Push_Exception_InvalidToken</entry>
  111. <entry>Any form of an invalid token will be if the
  112. device is no longer subscribed, inactive or not
  113. valid.</entry>
  114. <entry>In some cases you may attempt to resend in an
  115. hour; this will be stated in the exception.
  116. Otherwise you will want to remove the token from
  117. being sent to again.</entry>
  118. </row>
  119. <row>
  120. <entry>Zend_Mobile_Push_Exception_QuotaExceeded</entry>
  121. <entry>You have reached the per-day throttling.</entry>
  122. <entry>Per-day throttling is only on unauthenticated web
  123. services; you will need to <ulink
  124. url="http://msdn.microsoft.com/en-us/library/ff941099(v=vs.92).aspx">register
  125. your application for notifications</ulink>.</entry>
  126. </row>
  127. </tbody>
  128. </tgroup>
  129. </table>
  130. </sect2>
  131. <sect2 id="zend.mobile.push.mpns.message">
  132. <title>Advanced Messages</title>
  133. <para>
  134. MPNS provides the ability for sending more advanced messages; for
  135. instance the examples above show the most basic implementation of a
  136. message. Zend_Mobile_Push_Message_Mpns_* allows you to do far more
  137. advanced messaging outlined below.
  138. </para>
  139. <sect3 id="zend.mobile.push.mpns.message.tile">
  140. <title>Tile Messages</title>
  141. <para>
  142. Tile messages have additional optional attributes for Windows
  143. Phone 7.1+; you must ensure that you are sending to a device
  144. with the proper version otherwise your notification will fail.
  145. </para>
  146. <programlisting language="php"><![CDATA[
  147. $message = new Zend_Mobile_Push_Message_Mpns_Tile();
  148. $message->setToken('http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN'); // REPLACE WITH NOTIFICATION URI FROM MPNS
  149. $message->setBackgroundImage('foo.jpg');
  150. $message->setCount(1);
  151. $message->setTitle('Bar');
  152. // other optional attributes for wp7.1+
  153. $message->setTileId('/Foo.xaml');
  154. $message->setBackBackgroundImage('blue.jpg');
  155. $message->setBackTitle('Bar');
  156. $message->setBackContent('Foo Bar');
  157. ]]></programlisting>
  158. </sect3>
  159. <sect3 id="zend.mobile.push.mpns.message.toast">
  160. <title>Toast Messages</title>
  161. <para>
  162. Toast messages have additional optional attributes for Windows
  163. Phone 7.1+; you must ensure that you are sending to a device
  164. with the proper version otherwise your notification will fail.
  165. </para>
  166. <programlisting language="php"><![CDATA[
  167. $message = new Zend_Mobile_Push_Message_Mpns_Toast();
  168. $message->setToken('http://sn1.notify.live.net/throttledthirdparty/01.00/THETOKEN'); // REPLACE WITH NOTIFICATION URI FROM MPNS
  169. $message->setTitle('Foo');
  170. $message->setMessage('Bar');
  171. // optional attributes for wp7.1+
  172. $message->setParams('?bar=foo'); //optional parameters
  173. ]]></programlisting>
  174. </sect3>
  175. </sect2>
  176. </sect1>