【问题标题】:Apple Push Notification Service - change title of notification messageApple Push Notification Service - 更改通知消息的标题
【发布时间】:2012-08-05 20:28:39
【问题描述】:

我的 APNS 消息运行良好。但是,我想更改已发送消息的标题。目前标题始终是我的应用程序的名称。我看到原生 iOS“邮件”应用程序的通知将“发件人”地址作为消息的标题,并且电子邮件主题以粗体显示作为通知的子标题。我想为我的应用程序的通知重现此内容,但看不到如何执行此操作。 JSON 有效负载似乎只有一个“警报”键,而没有提及“标题”键。有没有可能实现我想要的?

【问题讨论】:

  • 我认为你不能那样做。在本机邮件应用程序中完成是因为它是由 Apple 制作的,正如您所说的那样......它是本机的。
  • 无法回答 :) 抱歉
  • 好的,谢谢大家的回复。

标签: ios json push-notification apple-push-notifications


【解决方案1】:

我只是偶然发现了这个老问题,只是想补充一下,现在可以为通知指定标题和正文(我认为是从 iOS 8 开始)。

您的推送负载需要如下所示:

{
  "aps": {
    "alert": {
        "title": "New Message from Boss",
        "body": "Can you complete the new feature until tomorrow, please?!"
    }
  }
}

您可以在 Apple 的 Local and Remove Notification Programming Guide 中找到详细规格。

【讨论】:

    【解决方案2】:

    无法更改 APNS 消息的标题。

    【讨论】:

      【解决方案3】:

      有可能!

      Message.php中的ApnsPHP_Message类需要稍微修改一下:

      // 标题的新变量

      protected $_titleText;
      

      //为title创建setter&getter方法

      public function setTitleText($sText)
      {
          $this->_titleText = $sText;
      }
      
      public function getTitleText()
      {
          return $this->_titleText;
      }
      

      //修改_getPayload方法

      protected function _getPayload()
      {
          $aPayload[self::APPLE_RESERVED_NAMESPACE] = array();
      
          if (isset($this->_sText)) {
      
              if(isset($this->_titleText)){
                  $aPayload[self::APPLE_RESERVED_NAMESPACE]['alert']['title'] = (string)$this->_titleText;
                  $aPayload[self::APPLE_RESERVED_NAMESPACE]['alert']['body'] = (string)$this->_sText; 
              }else{
                  $aPayload[self::APPLE_RESERVED_NAMESPACE]['alert'] = (string)$this->_sText;
              }
      
          }
          if (isset($this->_nBadge) && $this->_nBadge > 0) {
              $aPayload[self::APPLE_RESERVED_NAMESPACE]['badge'] = (int)$this->_nBadge;
          }
          if (isset($this->_sSound)) {
              $aPayload[self::APPLE_RESERVED_NAMESPACE]['sound'] = (string)$this->_sSound;
          }
      
          if (is_array($this->_aCustomProperties)) {
              foreach($this->_aCustomProperties as $sPropertyName => $mPropertyValue) {
                  $aPayload[$sPropertyName] = $mPropertyValue;
              }
          }
      
          return $aPayload;
      }
      

      通过此修改,您可以设置推送消息标题:

      $message->setTitleText("This is title");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-18
        • 1970-01-01
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 1970-01-01
        • 2013-01-14
        • 1970-01-01
        相关资源
        最近更新 更多