用户在一个视图中选择允许他发送通知的时间,例如上午9点。在另一个视图中,他选择可以发送通知的时间,例如,直到下午12点。我怎样才能做到这一点?我还是一个初学者,不太了解
@IBAction func saveButtonTapped(sender: UIButton) {
dateFormatter.dateFormat = "HH:mm"
UserSettings.userNotifFrom = dateFormatter.string(from: datePickerOutlet.date)
print(UserSettings.userNotifFrom!)
self.currentTimeOutlet.text = "Notifications are sent from: \(UserSettings.userNotifFrom!)"
}
我写了一个函数,但是我很确定它不能那样工作。我应该在哪里调用该函数?
func startSendingNotifications() {
if UserSettings.userNotifFrom != dateFormatter.string(from: datePickerOutlet.date) {
print("turned off notifications")
UIApplication.shared.unregisterForRemoteNotifications()
} else {
print("turn on notifications")
UIApplication.shared.registerForRemoteNotifications()
}
}