当我使用推送有效负载发送时,通知没有显示,mutable-content:1
它也没有命中通知服务扩展内的断点,虽然没有显示可变内容推送,但通知内容扩展也工作正常。我没有修改通知服务扩展中的代码,它是 Xcode 生成的默认代码。创建通知服务扩展时我是否遗漏了某些内容,或者可能是设备设置的问题?几天前我在同一台设备上进行了测试,通知服务扩展工作正常。
以下是我的服务扩展代码
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
编辑1:下面是我的推送有效载荷
{
"aps":{
"sound":"default",
"mutable-content": 1,
"category": "myCategory",
"alert":{
"body":"this is a custom push",
"subtitle":"subtitle of the push",
"title":"Push Test"
}
}
}
编辑1:问题似乎在运行在 10.2.1 上的特定设备上,我检查了在 10.2 上运行的其他设备,它触发了通知服务扩展。