1

我不知道如何在独立的 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

4

1 回答 1

0

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

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

因此,当我尝试为每天安排事件(365 天 = 365 个通知)时,我已经达到了 64 个通知的限制。

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

于 2020-04-14T01:43:44.927 回答