我在iPhone上运行了我的应用程序。 (只需连接手机,然后选择iPhone作为目标即可。)我在应用程序中构建了本地通知,这些通知已安排好并按时完美显示在iPhone上。但是,即使打开了“设置”->“通知”->“[我的应用]”->“在锁定屏幕上显示”下,它们也不会出现在锁定屏幕上。

奇怪的是,它们甚至出现在通知中心中。

这类似于UILocalNotification not showing in the lock screen,但是我也没有找到答案。

有人遇到过吗?我认为这可能是iOS错误。我正在使用最新的iOS,Xcode,OSX。

最佳答案

您必须获得许可才能在锁定屏幕上显示通知!一次查看Appdelegate.swift中的代码

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let notificationCategory = UIMutableUserNotificationCategory()
    let categories = Set<UIUserNotificationCategory>(arrayLiteral: notificationCategory)
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
    application.registerUserNotificationSettings(settings)
    return true
}

迅捷3

首先添加 import UserNotifications ,然后在中添加代码didFinishLaunchingWithOptions
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound , .badge]) {(accepted, error) in
            if !accepted {
                print("Notification access denied.")
            }
        }

关于ios - UILocalNotifications不会出现在锁定屏幕上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37381817/

10-10 21:09