UsernotificationCenter DidReceive не вызывается при нажатии на уведомление в CarPlayIOS

Программируем под IOS
Ответить
Anonymous
 UsernotificationCenter DidReceive не вызывается при нажатии на уведомление в CarPlay

Сообщение 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.>

Подробнее здесь: https://stackoverflow.com/questions/795 ... otificatio
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»