@Engineer
Thanks for reply. Some more crash info. On simulator (did not test on device at this stage).
Here is crash report:
Error occurs in #4 notifyMe IBAction
@IBAction func notifyMe(_ sender: UIButton) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus == .notDetermined {
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
DispatchQueue.main.async {
if !granted {
// Alert user
}
}
}
} else if settings.authorizationStatus == .denied {
DispatchQueue.main.async {
// Alert user
}
} else if settings.authorizationStatus == .authorized {
DispatchQueue.main.async {
self.alarmButton.isHidden = self.duree <= 120
}
}
})
var alertStyle = UIAlertController.Style.alert
let alertController = UIAlertController(
title: NSLocalizedString("M'avertir", comment: ""),
message: NSLocalizedString("Attention", comment: ""), preferredStyle: alertStyle)
var title = NSLocalizedString("5'", comment: "")
let ok = UIAlertAction(title: title, style: .default, handler: {(action) -> Void in
self.sendInitialNotification(beforeEnd: 5)
DispatchQueue.main.async { sender.isHidden = true }
})
alertController.addAction(ok)
let cancelAction = UIAlertAction(title: NSLocalizedString("Non", comment: ""), style: .default, handler: { (action) -> Void in
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
}
Crash apparently occurs on calling userNotificationCenter:
nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if notification.request.identifier == requestIdentifier {
completionHandler( [.alert,.sound,.badge])
}
}
Topic:
App & System Services
SubTopic:
Notifications
Tags: