当我发送带有推送负载的mutable-content:1时没有显示通知,它既没有显示可变内容推送,也没有显示Notification服务扩展中的断点,Notification内容扩展也是工作正常。我没有修改Notification服务扩展中的代码,它是由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"
}
}
}
EDIT1:这个问题似乎特定设备上运行的10.2.1,我检查了10.2上运行的其他设备,它触发了通知服务扩展。
你如何发送包含“mutable-content:1”的Json?如果它与FCM通过“_”更改“ - ” – SeikoTheWiz
Hi @SeikoTheWiz i我没有使用FCM – princerk
Hi @princerk我也在尝试实现通知服务扩展,但它并不修改我的内容,即使我使用的是默认的苹果代码 我是否需要为应用标识启用推送通知我为通知服务扩展? 请帮助我完成工作所需的步骤。 –