0

What I want that, I set the local notification for 7:00 am and as its fire immediately, notification comes continuously till the user not perform any action on notification or open the app.

below is code to send notification first time

 let alarmNotification: UNMutableNotificationContent = UNMutableNotificationContent()
 alarmNotification.title = "Demo"
 alarmNotification.body = "Test"
 alarmNotification.categoryIdentifier = "myDemoCategory"

 let now = Date()
 let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)
 let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
 let request = UNNotificationRequest(identifier: "TestNotification\(now)", content: alarmNotification, trigger: trigger)

 UNUserNotificationCenter.current().add(request) {(error) in
     if let error = error {         
           print("Uh oh! We had an error: \(error)")
     }
 }

Please suggest for continuous send local notification.

Thanks

iPhoneDev
  • 228
  • 1
  • 2
  • 9

1 Answers1

0

In your date component add seconds here

let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)

set number of notifications you want in loop for every second by incrementing seconds Max is 64 in iOS.

when notification is tapped dismiss all notifications and reset for next time.

  • Thanks for you answer. I tried that but what happened, I set alarm 12:28 and it fire till 12:28:59 not continuously. I want that notification comes continuously till user not touch the notification or app. as one app in app store "Alarmy" it fires continuously. – iPhoneDev Jul 21 '17 at 07:03
  • there is limitation with iOS that you have limited local notifications for your aap also there is no callback on receive of notification without user action – Akash Singh Sisodia Jul 21 '17 at 07:13
  • yes, I agree on that but one of the app on the app store alarmy app it gives continuously notification. – iPhoneDev Jul 21 '17 at 07:22
  • @iPhoneDev Did you find any solution of firing local notification every second. – Mubin Mall Dec 21 '22 at 05:55