IOSNotification.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. require_once('UmengNotification.php');
  3. abstract class IOSNotification extends UmengNotification {
  4. // The array for payload, please see API doc for more information
  5. protected $iosPayload = array(
  6. "aps" => array(
  7. "alert" => NULL
  8. //"badge" => xx,
  9. //"sound" => "xx",
  10. //"content-available" => xx
  11. )
  12. //"key1" => "value1",
  13. //"key2" => "value2"
  14. );
  15. // Keys can be set in the aps level
  16. protected $APS_KEYS = array("alert", "badge", "sound", "content-available");
  17. function __construct() {
  18. parent::__construct();
  19. $this->data["payload"] = $this->iosPayload;
  20. }
  21. // Set key/value for $data array, for the keys which can be set please see $DATA_KEYS, $PAYLOAD_KEYS, $BODY_KEYS, $POLICY_KEYS
  22. function setPredefinedKeyValue($key, $value) {
  23. if (!is_string($key))
  24. throw new Exception("key should be a string!");
  25. if (in_array($key, $this->DATA_KEYS)) {
  26. $this->data[$key] = $value;
  27. }
  28. else if (in_array($key, $this->APS_KEYS)) {
  29. $this->data["payload"]["aps"][$key] = $value;
  30. }
  31. else if (in_array($key, $this->POLICY_KEYS)) {
  32. $this->data["policy"][$key] = $value;
  33. }
  34. else
  35. {
  36. if ($key == "payload" || $key == "policy" || $key == "aps") {
  37. throw new Exception("You don't need to set value for ${key} , just set values for the sub keys in it.");
  38. } else {
  39. throw new Exception("Unknown key: ${key}");
  40. }
  41. }
  42. }
  43. // Set extra key/value for Android notification
  44. function setCustomizedField($key, $value) {
  45. if (!is_string($key))
  46. throw new Exception("key should be a string!");
  47. $this->data["payload"][$key] = $value;
  48. }
  49. }