首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UNUserNotification从不出现在预定的较晚日期

UNUserNotification从不出现在预定的较晚日期
EN

Stack Overflow用户
提问于 2017-04-10 13:43:31
回答 1查看 221关注 0票数 1

通知是在我安排在未来一个较近的日期(如1小时后)时显示的,但当我计划明天或晚些时候时,通知就不会显示在我的真实数据上。对为什么会发生这种事有什么想法吗?我再次检查了trigger.nextTriggerDate(),它们是正确的

这是我的密码:

代码语言:javascript
复制
@available(iOS 10.0, *)
class func scheduleWith(episode: Episode, dateInfo: DateComponents) {
    let content = UNMutableNotificationContent()
    content.title = episode.title
    content.body = episode.overview

    content.userInfo = ["id": episode.id]
    content.categoryIdentifier = Notify.category.episodes.str

    let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: false)

    let request = UNNotificationRequest(identifier: Notify.identifier.episode.str, content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
        if let error = error {
            print(error)
        }
        else {
            print("date info", dateInfo.date)
            print("trigger", trigger.nextTriggerDate()!)
        }
    })
}

下面是我如何创建dateInfo的方法:

代码语言:javascript
复制
let greg = Calendar.current
var components = DateComponents()
components.setValue(-15, for: .minute)

guard let date = ep.firstAired as Date? else { return }
guard let alertDate = greg.date(byAdding: components, to: date) else { return }

let dateInfo = Calendar.current.dateComponents([.year,.month,.day,.hour,.minute,.second], from: alertDate)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-10 14:41:12

在通知中使用相同的标识符。您需要为循环中的每个通知指定不同的标识符。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43324900

复制
相关文章

相似问题

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