最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - userNotificationCenter didReceive is not being called when tapping a notification in carplay - Stack Overflow

programmeradmin3浏览0评论

I have set the following for notification in PermissionViewcontroller file:

UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .alert, .badge,.carPlay]) { (granted, error) in
}

Then configure actions when tap notification in iPhone or in Carplay.

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()
}

Below method use for display carplay notification

 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.")
            }
        }
    })
}

using this method notification display successfully in carplay but when i tapped in notification banner in carplay at that time below method not called.But for iPhone it's working fine.

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) 

So any one have solution for carplay notification tap event not working then help me.

Thank you Shraddha vaishnani

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论