iOS 10通知不显示警报

问题描述 投票:1回答:1

代码非常简单:

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,如下所示:enter image description here

但在iOS 10上,警报未显示。

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

我的Xcode版本是9.2(9C40b)

任何帮助表示赞赏。

xcode ios10 ios11 unnotificationrequest
1个回答
2
投票

尝试添加这样的通知正文

content.body = "Any text/Blank Space"

希望对你有帮助

© www.soinside.com 2019 - 2024. All rights reserved.