首页 > 解决方案 > 在接收推送通知 IOS 13.2.2 和 watch os 6.1 时向 Apple Watch 延迟通知

问题描述

嗨,我正在开发同时支持 iphone 和 watch 的应用程序。我正在注册来自 iphone 应用程序的用户通知,如下所示。在接收 PUsh 通知时,我可以在 1 到 2 秒内快速收到 iphone 通知。但是对于手表来说,它每次都会延迟 20 秒。我尝试取消配对并重新启动设备,但效果不佳请建议我应该怎么做才能在手表端快速获取通知。我正在使用 iOS 13.2.2 并观看操作系统 - 6.1

  {
        let approveAction = UIMutableUserNotificationAction()
        approveAction.title = NSLocalizedString("Approve", comment: "Notification approve button title")
        approveAction.identifier = "approve"
        approveAction.isDestructive = false
        approveAction.activationMode = .background
        approveAction.isAuthenticationRequired = false


        let denyAction = UIMutableUserNotificationAction()
        denyAction.title = NSLocalizedString("Deny", comment: "Notification deny button title")
        denyAction.identifier = "deny"
        denyAction.isDestructive = true
        denyAction.activationMode = .background
        denyAction.isAuthenticationRequired = false

        let signInCategory = UIMutableUserNotificationCategory()
        signInCategory.setActions([approveAction, denyAction], for: .default)
        signInCategory.identifier = "pushotp"

        let categories = NSSet(object: signInCategory) as? Set<UIUserNotificationCategory>

        let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: categories)
        DispatchQueue.main.async(execute: {
            UIApplication.shared.registerUserNotificationSettings(settings)
        })
    } 

标签: iospush-notificationunusernotificationcenterusernotificationswatchos-6

解决方案


推荐阅读