Reputation: 5248
The code is very easy:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (granted, error) in
if !granted {
print("Not allowed")
}
})
let content = UNMutableNotificationContent()
content.title = "Alert"
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 20, repeats: false)
let request = UNNotificationRequest(identifier: "test", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
return true
}
It works well on iOS 11, like this:
but on iOS 10, the alert doesn't show.
On both iOS 10 and iOS 11, the sound did appear.
My Xcode version is 9.2(9C40b)
Any help is appreciated.
Upvotes: 1
Views: 66
Reputation: 912
Try to add the body of notification like this
content.body = "Any text/Blank Space"
Hope this will help you
Upvotes: 3