Search code examples
swiftuilocalnotification

How to create a critical locale notification in Swift


I try to create a critical locale notification

Hi,

I try to create a critical locale notification like this :

critical notification

I tried this but it doesn't work:

let newNotification = UNMutableNotificationContent()
        newNotification.title = "Taskko"
        newNotification.body = textNotification
        newNotification.sound = .defaultCritical
        newNotification.badge = (UserDefaults.standard.integer(forKey: "counterOfNotif")) as NSNumber
        newNotification.interruptionLevel =  .critical 

I searched on the internet but I didn't find how to do it


Solution

  • Critical notifications require a special entitlement from Apple and are used for apps such as medical alerts. My French isn’t great, but I don’t think Twitter will be sending critical notifications for live podcasts :-)

    I think you are actually wanting to use a time-sensitive notification. That has an interruptionLevel of .timeSensitive and also requires an additional entitlement. However you can configure the entitlement yourself in Xcode. See How to enable iOS time-sensitive notifications switch in app settings?

    You also won’t be able to use the .defaultCritical sound without the special entitlement from Apple.

    If you really do want to use critical alerts you can request the entitlement here: https://developer.apple.com/contact/request/notifications-critical-alerts-entitlement/ (requires Apple developer login).