In my app I am scheduling local notifications with the following method:
func addNotificationRequest(fireDate: Date, identifier: String, sound: UNNotificationSound)
{
let notificationCenter = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Important"
content.body = notificationMessage
content.sound = sound
content.categoryIdentifier = "UserActions"
let calendar = Calendar(identifier: .gregorian)
let triggerDate = calendar.dateComponents([.hour, .minute, .second], from: fireDate)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate, repeats: true)
let notificationRequest = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
notificationCenter.add(notificationRequest) { error in
if let error = error
{
print(error.localizedDescription)
}
}
let myAction = UNNotificationAction(identifier: "MyActionID", title: "Open", options: [.foreground])
let category = UNNotificationCategory(identifier: "UserActions", actions: [myAction], intentIdentifiers: [], options: [])
notificationCenter.setNotificationCategories([category])
}
Notifications are supposed to fire at a given time and should repeat every day at the same time.
On iOS 13 I found a bug that can be reproduced by the following steps:
- I go to iOS Settings > Notifications > App Name > Disable "Allow Notifications"
- Then I open the app and schedule a local notification for example after 2 minutes
- After that I go back to Settings and enable back "Allow Notifications" switch.
- After 2 minutes no local notification is shown. Tested it on older iOS versions and notifications are shown as supposed.
Maybe some people found this bug too and have any advice how to fix. Any help is appreciated.
true
, then schedule the notification. - Starsky