【问题标题】:Local Notifications not working on independent WatchOS App本地通知不适用于独立 WatchOS 应用程序
【发布时间】:2020-04-12 20:15:13
【问题描述】:

我不知道如何在独立的 WatchOS APP 中安排本地通知

在我的扩展委托中,我尝试设置它

let center = UNUserNotificationCenter.current()  

    func applicationDidFinishLaunching() {  

        center.delegate = self  
        let options: UNAuthorizationOptions = [.alert, .badge, .sound]  
        center.requestAuthorization(options: options) { (granted, error) in  
            if granted {  
                WKExtension.shared().registerForRemoteNotifications()  
            }  
        }  
    }  

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

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {  
        completionHandler([.alert, .sound,.badge])  
    }  

这是日程安排代码:

let content = UNMutableNotificationContent()  
                            content.title = "Meniny Oslavuje"  
                            content.body = nameEntry.name  

                            var dateComponents = DateComponents()  
                            dateComponents.month = dateNameEntry.month  
                            dateComponents.day = dateNameEntry.day  
                            dateComponents.hour = self.reminderTimeHour  
                            dateComponents.minute = self.reminderTimeMinute  

                            let trigger = UNCalendarNotificationTrigger(dateMatching:dateComponents , repeats: true)  
                            let request = UNNotificationRequest(identifier: uuid.uuidString, content: content, trigger: trigger)  
                            center.removeAllPendingNotificationRequests()  
                            center.add(request) { (err) in  
                                print(err)  
                            }  

来源: https://forums.developer.apple.com/message/414391#414391

【问题讨论】:

  • 源链接已损坏。您从哪里安排此特定通知? dataNameEntry 的值是什么?

标签: swiftui watchkit apple-watch unnotificationrequest watchos-6


【解决方案1】:

所以,问题在于我可以发送的通知数量。

我正在构建基于事件的应用程序,我知道每天都会发生什么事件。

因此,当我尝试为每天安排活动时(365 天 = 365 条通知),我已达到 64 条通知限制。

由于我们现在是四月,我的通知无法触发...因为它远远落后于 64 天...

【讨论】:

    猜你喜欢
    • 2021-06-08
    • 2021-04-10
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 2021-02-10
    • 1970-01-01
    相关资源
    最近更新 更多