Я работаю над приложением iOS с расширением службы уведомлений, чтобы изменять контент уведомления push. Метод расширения DidReceive (_: withContentHandler

[*] среда тестирования : ios simulator (например, iPhone 15, ios 18.0)
[*] :
[*]
Код: Выделить всё
xcrun simctl push booted com.domain.dev notification.json
< /code>
[list]
полезная нагрузка (notification.json
[/list]
Код: Выделить всё
{
"aps": {
"alert": {
"title": "Test Notification",
"body": "This is a test push notification."
},
"mutable-content": 1
},
"customData": {
"key": "value"
}
}
< /code>
[list]
[*][b]notificationservice.swift[/b]:
< /ul>
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override init() {
super.init()
print("NotificationService: Extension initialized at \(Date())")
}
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
print("NotificationService: didReceive called with request: \(request)")
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
bestAttemptContent.title = "\(bestAttemptContent.title) [Modified]"
contentHandler(bestAttemptContent)
} else {
contentHandler(request.content)
}
}
override func serviceExtensionTimeWillExpire() {
print("NotificationService: Time will expire")
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
- Проверенный «mitable-content»: 1 в полезной нагрузке.
- обеспечил расширение в приложении в «Brameworks, библиотеках и встроенном контенте» с изначальным знаком » Почему не является DidReceive (_: withContentHandler
при использовании xcrun simctl push в симуляторе? Simulator? В идеале я бы увидел операторы Print в консоли, подтверждающие, что расширение запускается и обрабатывает запрос. [например, 18.0]
- В настоящее время группы приложений не настроено - это требуется?
Подробнее здесь: https://stackoverflow.com/questions/795 ... with-xcrun