Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited tags; edited title
Link
rmaddy
  • 319.5k
  • 44
  • 548
  • 591

Launch a local notification at a specific time Xcode, swift 3in iOS

Source Link
imjonu
  • 515
  • 1
  • 6
  • 12

Launch a local notification at a specific time Xcode, swift 3

I am trying to create a timer which triggers a local notification to go off at a time that the user has set. The issue I am having is that I cannot figure out a way to be able to set the local notification to go off at say 7:00PM. Almost all the methods found when researching this issue involved the local notification going off at a certain amount of time from the current date. I am trying to allow the user to select 7:00PM and then have the notification go off at that time. Logically it makes sense that this can be achieved through having the final time (selected value by the user) - current time which would give you the time difference. I am however not entirely sure how to do this.

Any help with regard to the topic will be very much appreciated, thank you. Below is the code which I am currently using to trigger a local notification.

let center = UNUserNotificationCenter.current() content.title = storedMessage content.body = "Drag down to reset or disable alarm" content.categoryIdentifier = "alarm" content.userInfo = ["customData": "fizzbuzz"] content.sound = UNNotificationSound.init(named: "1.mp3") content.badge = 1 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeAmount, repeats: false) let request = UNNotificationRequest(identifier: "requestAlarm", content: content, trigger: trigger) center.add(request) center.delegate = self