Я добавил расширение службы уведомлений в свой проект и хочу отредактировать уведомления после того, как они прибыли в приложение: < /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
Расширение службы уведомлений не может редактировать уведомления ⇐ IOS
Программируем под IOS
-
Anonymous
1743350506
Anonymous
Я добавил расширение службы уведомлений в свой проект и хочу отредактировать уведомления после того, как они прибыли в приложение: < /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>
Проблема в том, что я не вижу текста [модифицированного] в уведомлении. Вы хоть представляете, в чем проблема или что может ее вызвать?
Подробнее здесь: [url]https://stackoverflow.com/questions/79544839/notification-service-extension-cant-edit-notifications[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия