iOS 10 UNNotification 不显示警报

iOS 10 UNNotification doesn't show alert

代码很简单:

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 11 上运行良好,如下所示:

但是在 iOS 10,警报没有显示。

在 iOS 10 和 iOS 11 上,声音都出现了。

我的Xcode版本是9.2(9C40b)

感谢任何帮助。

尝试像这样添加通知正文

content.body = "Any text/Blank Space"

希望对您有所帮助