//this method start send notification after one minutes , i want method for start notification after given time period and repeat itself after 2 second.
import UIKit
import UserNotifications
class ViewController: UIViewController{
let notification = UNUserNotificationCenter.current()
override func viewDidLoad() {
super.viewDidLoad()
notification.requestAuthorization(options: [.alert,.sound,.badge]){ isAccess, error in
if isAccess , error == nil {
var second = 60
for _ in 0...31 {
self.sendNotificationOnDate(second: &second)
}
}
else{
print("not access")
}
}
notification.delegate = self
}
func sendNotificationOnDate(second: inout Int){
let id = UUID().uuidString
let content = UNMutableNotificationContent()
content.title = "Alarm present"
content.body = " Alarm \(second)"
content.sound = .default
content.threadIdentifier = ""
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(second) , repeats: false)
second += 2
let request = UNNotificationRequest(identifier: id, content: content, trigger: trigger)
notification.add(request) { error in
self.notification.removeAllDeliveredNotifications()
}
}
}