Я добавил расширение службы уведомлений в свой проект и хочу отредактировать уведомления после того, как они прибыли в приложение: < /p>
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]"
bestAttemptContent.body = "\(bestAttemptContent.body) [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)
}
}
}
< /code>
Так я называю уведомлениями (для тестирования): < /p>
var apn = require('apn');
var apnProvider = new apn.Provider({
token: {
key: '*****.p8',
keyId: '*******',
teamId: '*******'
},
production: false
});
var deviceToken = '*******';
var notification = new apn.Notification();
notification.topic = '*******';
notification.expiry = Math.floor(Date.now() / 1000) + 3600;
notification.badge = 1;
notification.sound = 'Notification_1.wav';
notification.mutableContent = true;
notification.alert = {
title: "This is the title",
body: "This is the body"
};
notification.payload = {
type: "*******",
from: "*******",
groupId: "*******",
fetchData: {
id: "*******",
type: "*******"
}
};
console.log(notification.compile());
apnProvider.send(notification, deviceToken).then(function(result) {
console.log(JSON.stringify(result, null, 2));
process.exit(0);
});
< /code>
Проблема в том, что я не вижу текста [модифицированного] в уведомлении. Вы хоть представляете, в чем проблема или что может ее вызвать?
Подробнее здесь: https://stackoverflow.com/questions/795 ... ifications