【问题标题】:can UNUserNotificationCenter add multiple requests?UNUserNotificationCenter 可以添加多个请求吗?
【发布时间】:2019-11-21 08:31:17
【问题描述】:

我可以添加一个请求。但是当我尝试添加两个广告时,只有最新的被解雇了。第一个只是没有出现。这是我的方法:

            var triggerDailyEnd = DateComponents()
            triggerDailyEnd.hour = hour
            triggerDailyEnd.minute = minutes
            triggerDailyEnd.weekday = i+1
            // this repeat every day
            let triggerEnd = UNCalendarNotificationTrigger(dateMatching: triggerDailyEnd, repeats: true)

            let identifierEnd = getNotificationId(i+1, hour, minutes,true)
            let requestEnd = UNNotificationRequest(identifier: identifierEnd, content: notifEnd, trigger: triggerEnd)

            notificationCenter.add(requestEnd)

            var triggerDailyStart = DateComponents()
            triggerDailyStart.hour = hour
            // correctly remove time
            triggerDailyStart.minute = minutes-Int(ProgrammationViewController.PREHEAT_TIME)
            triggerDailyStart.weekday = i+1
            // this repeat every day
            let triggerStart = UNCalendarNotificationTrigger(dateMatching: triggerDailyStart, repeats: true)

            let identifierStart = getNotificationId(i+1, hour, minutes,false)
            let requestStart = UNNotificationRequest(identifier: identifierStart, content: notifStart, trigger: triggerStart)

            notificationCenter.add(requestStart)

代码很简单。当我在requestStart之后添加requestEnd时,会触发requestEnd的通知而不是requestStart。反之亦然。奇怪吗?

【问题讨论】:

    标签: ios swift unusernotificationcenter usernotifications nsusernotification


    【解决方案1】:

    请求的identifier 参数需要是唯一的。如果相同,第二个请求将覆盖第一个。

    【讨论】:

      猜你喜欢
      • 2016-09-13
      • 2016-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多