【问题标题】:Header(Bold text) and body in iOS Push notificationsiOS推送通知中的标题(粗体文本)和正文
【发布时间】:2017-01-24 13:57:13
【问题描述】:

我想知道我们如何在 iOS 推送通知中包含粗体文本。我在下面附上了一张示例图片。

就像睡觉时间一样,我想触发推送通知,标题为粗体文本,正文为普通文本,例如“保持一致:15 分钟后上床睡觉”

我看到许多其他应用程序也这样做。

【问题讨论】:

    标签: ios iphone push-notification formatting apple-push-notifications


    【解决方案1】:

    来自: bold (or other formatting) in iOS push notification

    iOS 推送通知中没有富文本功能。

    iOS 8.2 plus 的替代方案可能是使用“标题”来显示发件人的姓名,并将新消息放在正文中。例如,尝试这样的有效负载:

    {
        "aps": {
            "alert": {
                "title": "Jim",
                "body": "Hey bob"
            },
            "badge": 2
        }
    }
    

    【讨论】:

    • 在其他问题中看到了答案并试了一下。虽然没有工作。除此以外,是否还有其他必须包含的设置或参数?
    【解决方案2】:

    您可以通过发送静默推送消息然后在您的应用中触发本地通知来实现它。后半部分的代码如下:

    let content = UNMutableNotificationContent()
    content.title = "Bold title"
    content.body = "regular text"
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1.0, repeats: false)
    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    let center = UNNotificationCenter.current()
    center.add(request)
    

    【讨论】:

      猜你喜欢
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      相关资源
      最近更新 更多