[英]Local Notifications not working on independent WatchOS App
I cannot figure out, how I can schedule local notification in independent WatchOS APP我不知道如何在独立的 WatchOS APP 中安排本地通知
In my extension delegate I try to setup it在我的扩展委托中,我尝试设置它
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])
}
And this is schedule code:这是时间表代码:
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)
}
Source: https://forums.developer.apple.com/message/414391#414391来源: https://forums.developer.apple.com/message/414391#414391
So, issue is with number of notification I can send.所以,问题在于我可以发送的通知数量。
I am building event based app, where I know what event happens every day.我正在构建基于事件的应用程序,我知道每天都会发生什么事件。
Therefore When I tried to schedule event for each day (365days = 365 notitifications) I've reached 64notification limit.因此,当我尝试为每天安排事件(365 天 = 365 个通知)时,我已经达到了 64 个通知的限制。
And as we are now in april, my notification could not be trigger...as its far behind 64 days...由于我们现在是四月,我的通知无法触发……因为它远远落后于 64 天……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.