Apple has approve my request for an entitlement to use critical alerts. I attached my entitlement to my bundle identifier and created a provisioning profile and manually signed my app according to Apple's instructions: https://help.apple.com/developer-account/#/dev38c81d4cd
I also added a properties.entitlements file with the correctly modified bundle identifier and boolean "YES". My "Build Settings" does not have a "Code Signing Entitlements" within "Signing".
When I run the code below, I get the prompt to accept alerts, but then no critical alert. Any suggestions? Thanks!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var authOptions: UNAuthorizationOptions?
if #available(iOS 12.0, *) {
authOptions = [.alert, .badge, .sound, .criticalAlert]
} else {
authOptions = [.alert, .badge, .sound]
}
UNUserNotificationCenter.current().requestAuthorization(options:
authOptions!) { (granted, error) in
if !granted {
print("The application requires Notifications permission to display push notifications. Please enable it in settings.")
} else {
let userNotificationCenter = UNUserNotificationCenter.current()
var contentTitle:String?
var contentMessage:String?
var contentSound:UNNotificationSound?
contentTitle = "Message:"
contentMessage = "Critical Alert!"
contentSound = .defaultCritical
let content = UNMutableNotificationContent()
content.title = contentTitle!
content.subtitle = contentMessage!
content.sound = contentSound
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
userNotificationCenter.add(request)
}
}
}
}