代码非常简单:
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
}
但是在iOS 10上,警报不会显示。
在iOS 10和iOS 11上,声音确实出现了。
我的Xcode版本是9.2(9C40b)
感谢您的帮助。
答案 0 :(得分:2)
尝试添加这样的通知正文
content.body = "Any text/Blank Space"
希望这对您有帮助