【问题标题】:Usernotification when the screen is locked屏幕锁定时的用户通知
【发布时间】:2018-04-17 20:34:34
【问题描述】:

我想设置通知触发,即使屏幕被锁定。 代码:

let request = UNNotificationRequest(identifier: String(index), content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request, withCompletionHandler: nil)

当应用程序在后台时,它就像一个魅力。但是当屏幕锁定时,没有振动,也没有声音。好像通知没有送达。我怎样才能做到这一点?

【问题讨论】:

    标签: ios swift notifications


    【解决方案1】:

    您需要获得用户的许可才能在锁定屏幕上显示通知:

    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound , .badge]) {(accepted, error) in
         if !accepted {
                // notification access denied
         }
    }
    

    【讨论】:

    • 我已经要求警报和声音。我添加了 .badge,现在可以使用了,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2021-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多