D
D
Denis Antukh2020-08-07 05:07:12
iOS
Denis Antukh, 2020-08-07 05:07:12

Swift How to set local notifications every day except today?

How can I make notifications show every day at the specified time, except for today?
There is a code that displays notifications every day at 10:30:

//Center
        let center = UNUserNotificationCenter.current()
        center.removeAllPendingNotificationRequests()
        
        //Content
        let content = UNMutableNotificationContent()
        content.title = "Заголовок"
        content.body = "Текст"
        content.categoryIdentifier = "alarm"
        content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "inflicted.mp3"))
        content.badge = 1
        
        //Trigger
        var dateComponents = DateComponents()
        dateComponents.hour = 10
        dateComponents.minute = 30
        
        let triggerDate = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
        
        //Set
        let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: triggerDate)
        center.add(request)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vorobei, 2020-08-07
@antyxweb

You need to set notifications manually , no repeater with custom triggers.
Don't forget to limit the number of local notifications.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question