gpt4 book ai didi

iOS 11-用户本地通知每 x 分钟重复一次

转载 作者:行者123 更新时间:2023-11-30 12:10:44 25 4
gpt4 key购买 nike

在 iOS 11 中,如何实现每 x 分钟重复一次的本地通知?

重复间隔将由用户选择。例如,假设用户选择设置一个通知,该通知将在明天上午 9:00 触发,从那里开始每 2 天(或两周或 6 个月或 10 分钟)触发一次

var repeatInterval = Bool()

trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: repeatInterval)

//Schedule the Notification
let identifier = titleNospace
let request = UNNotificationRequest(identifier: identifier!, content: content, trigger: trigger)
self.center.add(request, withCompletionHandler: { (error) in
if let error = error {
print(error.localizedDescription)
}
})
UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: nil)

使用此代码,我可以在设定的日期安排通知。有人告诉我,从这里开始,如果我想安排重复通知,我应该在发送通知时使用triggerInterval。但我怎样才能这样做呢?如何获取通知发送时的重复时间(由用户定义)的值?我可以用这个吗?:

func didReceive(_ notification: UNNotification)

我已经尝试过,但似乎从未被调用过。

我是 swift 的新手,我已经尝试过,但似乎找不到解决方案。我已经能够管理每小时、每月、每天和每年的重复。如果我想添加自定义重复,但我真的不知道该怎么做。

最佳答案

供您引用,您无法自定义重复时间间隔,例如每 2 分钟、10 分钟等。您必须使用 NSCalendarUnit 的值就像

How to set repeat frequency in User Notification

关于iOS 11-用户本地通知每 x 分钟重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46094716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com