Я установил следующее для уведомления в файле разрешения.UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .alert, .badge,.carPlay]) { (granted, error) in
}
< /code>
Затем настройте действия, когда нажимайте уведомление на iPhone или в CarPlay. < /p>
func configureLocalNotification() {
let reply = UNTextInputNotificationAction(identifier: LocalNotification.Action.reply, title: "Reply".localized(), options: [])
let view = UNNotificationAction.init(identifier:LocalNotification.Action.viewMessage, title: "View In App", options: .foreground)
let dismiss = UNNotificationAction.init(identifier: LocalNotification.Action.dismiss, title: Localized.dismiss, options: [])
let textCategory = UNNotificationCategory(identifier: "chatCategory", actions: [reply,view,dismiss], intentIdentifiers: [], options: [.allowInCarPlay,.customDismissAction])
let call = UNNotificationAction.init(identifier: LocalNotification.Action.call, title: Localized.Voicemail.call, options: .foreground)
let callCategory = UNNotificationCategory(identifier: LocalNotification.Category.call, actions: [call,dismiss], intentIdentifiers: [], options: [])
let voicemailCategory = UNNotificationCategory(identifier: LocalNotification.Category.voicemail, actions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([textCategory, callCategory, voicemailCategory])
UNUserNotificationCenter.current().delegate = self
// registerNotificationCategories()
}
< /code>
Ниже метод Используйте для отображения уведомления CarPlay < /p>
func showCarPlayMessageNotification(userInfo: [AnyHashable: Any]) {
UNUserNotificationCenter.current().getNotificationSettings(completionHandler: {(settings) in
let content = UNMutableNotificationContent()
guard (settings.authorizationStatus == .authorized) else {
self.checkNotificationPermissions(localsettings: settings)
return // we should already been kick out of foreground at this point
}
if let aps = userInfo["aps"] as? [String: Any],
let alert = aps["alert"] as? [String: Any],
let title = alert["title"] as? String,
let body = alert["body"] as? String {
content.title = title
content.body = body
}
content.sound = UNNotificationSound.default
content.categoryIdentifier = "chatCategory"
//self.registerNotificationCategories()
let request = UNNotificationRequest(identifier: UUID().uuidString,
content: content,
trigger: nil)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Failed to show CarPlay notification: \(error)")
} else {
print("CarPlay notification displayed successfully.")
}
}
})
}
< /code>
Использование этого метода уведомления успешно отображается в CarPlay, но когда я использовал баннер уведомлений в CarPlay в то время ниже метода, не вызываемого. Но для iPhone он работает нормально. < /p>
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
< /code>
Таким образом, у кого -то есть решение для уведомления CarPlay.>
Подробнее здесь: https://stackoverflow.com/questions/795 ... otificatio
UsernotificationCenter DidReceive не вызывается при нажатии на уведомление в CarPlay ⇐ IOS
Программируем под IOS
1743433376
Anonymous
Я установил следующее для уведомления в файле разрешения.UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .alert, .badge,.carPlay]) { (granted, error) in
}
< /code>
Затем настройте действия, когда нажимайте уведомление на iPhone или в CarPlay. < /p>
func configureLocalNotification() {
let reply = UNTextInputNotificationAction(identifier: LocalNotification.Action.reply, title: "Reply".localized(), options: [])
let view = UNNotificationAction.init(identifier:LocalNotification.Action.viewMessage, title: "View In App", options: .foreground)
let dismiss = UNNotificationAction.init(identifier: LocalNotification.Action.dismiss, title: Localized.dismiss, options: [])
let textCategory = UNNotificationCategory(identifier: "chatCategory", actions: [reply,view,dismiss], intentIdentifiers: [], options: [.allowInCarPlay,.customDismissAction])
let call = UNNotificationAction.init(identifier: LocalNotification.Action.call, title: Localized.Voicemail.call, options: .foreground)
let callCategory = UNNotificationCategory(identifier: LocalNotification.Category.call, actions: [call,dismiss], intentIdentifiers: [], options: [])
let voicemailCategory = UNNotificationCategory(identifier: LocalNotification.Category.voicemail, actions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([textCategory, callCategory, voicemailCategory])
UNUserNotificationCenter.current().delegate = self
// registerNotificationCategories()
}
< /code>
Ниже метод Используйте для отображения уведомления CarPlay < /p>
func showCarPlayMessageNotification(userInfo: [AnyHashable: Any]) {
UNUserNotificationCenter.current().getNotificationSettings(completionHandler: {(settings) in
let content = UNMutableNotificationContent()
guard (settings.authorizationStatus == .authorized) else {
self.checkNotificationPermissions(localsettings: settings)
return // we should already been kick out of foreground at this point
}
if let aps = userInfo["aps"] as? [String: Any],
let alert = aps["alert"] as? [String: Any],
let title = alert["title"] as? String,
let body = alert["body"] as? String {
content.title = title
content.body = body
}
content.sound = UNNotificationSound.default
content.categoryIdentifier = "chatCategory"
//self.registerNotificationCategories()
let request = UNNotificationRequest(identifier: UUID().uuidString,
content: content,
trigger: nil)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Failed to show CarPlay notification: \(error)")
} else {
print("CarPlay notification displayed successfully.")
}
}
})
}
< /code>
Использование этого метода уведомления успешно отображается в CarPlay, но когда я использовал баннер уведомлений в CarPlay в то время ниже метода, не вызываемого. Но для iPhone он работает нормально. < /p>
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
< /code>
Таким образом, у кого -то есть решение для уведомления CarPlay.>
Подробнее здесь: [url]https://stackoverflow.com/questions/79546581/usernotificationcenter-didreceive-is-not-being-called-when-tapping-a-notificatio[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия