首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UNNotificationTrigger关于fireDate

UNNotificationTrigger关于fireDate
EN

Stack Overflow用户
提问于 2016-12-15 03:29:39
回答 1查看 2.2K关注 0票数 2

在iOS 10中,我使用新的frameWork UNNotification .When设置UNNotificationTrigger,我想在UNNotification上设置一个点火日期。但我找不到在UNNotificationTrigger的属性中设置点火日期。那么我如何在UNNotificationTrigger中设置一个火日期呢?我想在UNNotificationTrigger中设定一个点火日期,我如何设置?

EN

回答 1

Stack Overflow用户

发布于 2016-12-15 06:03:24

用户通知框架中有两种类型的触发器:

  1. UNTimeIntervalNotificationTrigger -用于创建具有设置间隔时间的通知: 30分钟内开火(60秒乘30), 让触发器= UNTimeIntervalNotificationTrigger(timeInterval:(30*60),重复:false
  2. 联合国宪兵notification用于在特定日期创建通知,就像在您的情况下那样,并用于以特定标准重复: 让date = DateComponents() date.hour =8 date.minute = 30 date.minute= UNCalendarNotificationTrigger(dateMatching: date,repeats: true)

您的解决方案(Swift 3)是将您的日期转换为dateComponent,这可以通过以下方法完成:

代码语言:javascript
复制
import UserNotifications

var newComponents = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second,], from: date)

let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41155967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档