I am working on alarm application. I had used local notification to notify user, it's working fine when application is in foreground or in background but when I locked the screen at that time notification arrived but notification sound is overlapped. Overlapped issue occurred only when device is locked.
I am referring Alarmy app which is live ans working fine in same scenario even it's also play sound when device is silent mode.
I had also refer asked question related Alarmy App but it did not help me.
I am stuck in this issue don't know what to do because it's playing sound without overlapped when screen is not locked. And I can't play any sound through code when local notification arrive, ringing sound completely depend local notification.
Below is code by which I'm setting local notifications,
func add(alarm: Alarm) -> Void {
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
let identifier = "\(alarm.id)"
let content = UNMutableNotificationContent()
content.title = applicationName
content.body = alarm.label
content.categoryIdentifier = identifier
var dict = [String: Any]()
dict["id"] = alarm.id
dict["sun"] = alarm.sun
content.userInfo = dict
content.sound = UNNotificationSound.init(named: UNNotificationSoundName.init("\(alarm.soundName).wav"))
let interval = Date.init(timeIntervalSinceReferenceDate: TimeInterval.init(alarm.time))
var i = interval.timeIntervalSince(Date())
if i < 0 {
i = 1
}
for t in 1...60 {
let triggers = UNTimeIntervalNotificationTrigger.init(timeInterval: i + 6, repeats: false)
let requests = UNNotificationRequest.init(identifier: "kathla\(t)", content: content, trigger: triggers)
UNUserNotificationCenter.current().add(requests) { (error) in
if let error = error {
print(error.localizedDescription)
}
}
i = i + 5
}
}