这是iOS开发范畴 平台及工具:iOS,XCode,Swift。 框架:User Notifications。 我的想法是先通过UNCalendarNotificationTrigger达到某一时刻,触发本地通知,然后再使用UNTimeIntervalNotificationTrigger达到不断重复提醒的功能。 我不知道在UNCalendarNotificationTrigger被触发之后,如何UNTimeIntervalNotificationTrigger,如果有大神明白,还请指教。 简而言之就是到了指定时刻,闹钟就不断地响,如果知道这一功能如何实现,也可告知。
1条回答 默认 最新
米粒 2023-03-11 10:48关注//创建一个UNCalendarNotificationTrigger触发器,在指定时间触发本地通知 let content = UNMutableNotificationContent() content.title = "闹钟" content.body = "该起床了" let dateComponents = DateComponents(hour: 7, minute: 30) let calendarTrigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false) let request = UNNotificationRequest(identifier: "calendarNotification", content: content, trigger: calendarTrigger) UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) //创建一个UNTimeIntervalNotificationTrigger触发器,在指定时间间隔后触发通知 let intervalTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true) let intervalContent = UNMutableNotificationContent() intervalContent.title = "提醒" intervalContent.body = "该做点事情了" let intervalRequest = UNNotificationRequest(identifier: "intervalNotification", content: intervalContent, trigger: intervalTrigger) //在UNCalendarNotificationTrigger触发本地通知后,添加一个带有时间间隔触发器的新通知,以便在触发器触发时,显示新的通知。 UNUserNotificationCenter.current().add(intervalRequest, withCompletionHandler: nil) ```swift```
解决 无用评论 打赏 举报