2

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

enter image description here

就像时间睡觉我想触发以大胆文字的标题和普通文本的身体像推送通知“保持一致:在15分钟内上床”

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

回答

1

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

有一个在iOS的推送通知没有富文本的功能。

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

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

看到其他一些问题的答案,并试了一下。虽然没有工作。除此之外是否还有其他设置或参数? –

0

您可以通过发送一个无声推送消息的实现,然后触发您的应用程序的本地通知。后一部分的代码如下所示:

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)