IOSNotification1.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. require_once(APP_ROOT_PATH. 'system/umeng/notification/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. "type" => NULL,
  13. //"key1" => "value1",
  14. //"key2" => "value2"
  15. );
  16. // Keys can be set in the aps level
  17. protected $APS_KEYS = array("alert", "badge", "sound", "content-available");
  18. function __construct() {
  19. parent::__construct();
  20. $this->data["payload"] = $this->iosPayload;
  21. }
  22. // Set key/value for $data array, for the keys which can be set please see $DATA_KEYS, $PAYLOAD_KEYS, $BODY_KEYS, $POLICY_KEYS
  23. function setPredefinedKeyValue($key, $value) {
  24. if (!is_string($key))
  25. throw new Exception("key should be a string!");
  26. if (in_array($key, $this->DATA_KEYS)) {
  27. $this->data[$key] = $value;
  28. } else if (in_array($key, $this->APS_KEYS)) {
  29. $this->data["payload"]["aps"][$key] = $value;
  30. } else if (in_array($key, $this->POLICY_KEYS)) {
  31. $this->data["policy"][$key] = $value;
  32. } else {
  33. if ($key == "payload" || $key == "policy" || $key == "aps") {
  34. throw new Exception("You don't need to set value for ${key} , just set values for the sub keys in it.");
  35. } else {
  36. throw new Exception("Unknown key: ${key}");
  37. }
  38. }
  39. }
  40. // Set extra key/value for Android notification
  41. function setCustomizedField($key, $value) {
  42. if (!is_string($key))
  43. throw new Exception("key should be a string!");
  44. $this->data["payload"][$key] = $value;
  45. }
  46. }