小编Мар*_*нов的帖子

从Swift 3中的日期选择器安排使用火灾日期的每周可重复本地通知

因此,我目前正在构建时间表应用程序,并且尝试创建本地通知以在每周的特定日期(每周的特定时间)触发。因此,我要做的第一件事是获取事件开始时间的日期值,然后从开始时间值中减去5分钟,然后安排通知。以前只需键入它就非常容易: notification.repeatInterval = CalendarUnit.WeekOfYear但是现在在Swift 3中不推荐使用该命令,是的,所以我发现的唯一方法是:

 let someMinutesEarlier = Calendar.current.date(byAdding: .minute, value: -5, to: startTimePicker.date)

        let contentOfNotification = UNMutableNotificationContent()

        let interval = someMinutesEarlier?.timeIntervalSinceNow

        contentOfNotification.title = "Event starting"
        contentOfNotification.body = "Some notes"
        contentOfNotification.sound = UNNotificationSound.default()

        let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: interval!, repeats: true)
        let request = UNNotificationRequest.init(identifier: notificationIdentifier, content: contentOfNotification, trigger: trigger)

        let center = UNUserNotificationCenter.current()
        center.add(request) { (error) in
            print(error as Any)
        }
Run Code Online (Sandbox Code Playgroud)

但是由于someMinutesEarlier中的年份,这仅安排了一次通知(无论重复布尔值设置为true),或者可能是其他原因?任何的想法?

notifications local repeat ios swift

1
推荐指数
1
解决办法
1624
查看次数

标签 统计

ios ×1

local ×1

notifications ×1

repeat ×1

swift ×1