简体   繁体   English

本地通知不适用于独立 WatchOS 应用程序

[英]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.

相关问题 在独立的 watchOS 应用上实现核心数据 - Implement Core Data on independent watchOS app 在独立的 watchOS 应用程序中使用 FCM 时出现问题 - Problem using FCM in an independent watchOS app 是否可以将 AppDelegate 添加到独立的 watchOS SwiftUI 应用程序? - Is it possible to add an AppDelegate to an independent watchOS SwiftUI app? 如何设置 SwiftUI 应用程序文件以允许在 WatchOS 6 上部署独立应用程序 - How to setup SwiftUI app file to allow independent app to deploy on WatchOS 6 WatchOS、SwiftUI:如何以“视图”作为正文发送本地通知 - WatchOS, SwiftUI: How to send local notifications with a 'View' as body 从 WidgetKit Complication (WatchOS 9) 访问 iOS App / WatchOS App 数据 - Access iOS App / WatchOS App data from WidgetKit Complication (WatchOS 9) 在 watchOS 应用程序布局方面寻求帮助 - Looking for assistance in watchOS app layout 提交 iOS 应用程序时 watchOS 应用程序出现问题 - Issue with watchOS app when submit iOS app WatchOS 上的 SwiftUI - 用于启动活动或锻炼应用程序的代码? - SwiftUI on WatchOS - code for launching Activity or Workout App? 在自己的应用程序/视图中接收本地通知(或如何在 SwiftUI 中注册 UNUserNotificationCenterDelegate ) - receive local notifications within own app / view (or how to register a UNUserNotificationCenterDelegate in SwiftUI )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM