如何安排在特定时间的通知,然后每隔x时间重复一次?

时间:2020-10-28 15:40:27

标签: swift xcode unnotificationrequest

我正在制作一个提醒应用程序,您可以在其中安排提醒时间,然后每隔x秒/分钟/小时/天等重复一次。

如果我希望它每x重复一次,我可以这样做:

func addNotification() {

let content = UNMutableNotificationContent()
content.title = "title"
// show this notification 5 minutes from now
var trigger: UNTimeIntervalNotificationTrigger
trigger = UNTimeIntervalNotificationTrigger(timeInterval: 300, repeats: true)
// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)

// add our notification request
UNUserNotificationCenter.current().add(request)

}

这实际上是我想要的,但我希望能够选择开始日期,而不是从现在开始5分钟,然后从该初始开始日期起每5分钟重复一次。

这可能吗?

1 个答案:

答案 0 :(得分:0)

据我所知,不可能在特定日期之后每隔X秒(或其他时间)重复一次通知。

我认为这里的“最佳”选项是改用def handle_downloadRequested(item): path, _ = QtWidgets.QFileDialog.getSaveFileName( None, "Save File", item.suggestedFileName() ) if path: item.setPath(path) item.accept() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) fig = go.Figure(data=[{"type": "scattergl", "y": [2, 1, 3, 1]}]) fig_view = show_qt(fig) fig_view.page().profile().downloadRequested.connect( handle_downloadRequested ) sys.exit(app.exec_()),并从给定日期开始安排60/5 = 12通知(每5秒发送1条通知)。

类似这样的东西:

UNCalendarNotificationTrigger

现在,基于此,您将需要在用户点击其中一个通知以取消所有其他通知时进行处理。但这是这里的另一个主题,我留给您自己找出逻辑。