gpt4 book ai didi

ios - 锁屏ios上的本地通知

转载 作者:行者123 更新时间:2023-11-30 11:35:59 25 4
gpt4 key购买 nike

我想在 iOS 中屏幕锁定时发送本地通知。下面是我添加的代码。但是当屏幕锁定时无法收到通知

let notification = UILocalNotification()
notification.alertAction = "Go back to App"
notification.alertBody = "Phone Found..!!"

notification.fireDate = NSDate(timeIntervalSinceNow: 1) as Date
UIApplication.shared.scheduleLocalNotification(notification)
notification.soundName = UILocalNotificationDefaultSoundName

请提出我所缺少的内容。预先感谢您。

最佳答案

您的代码有效,您必须增加时间间隔,UILocalNotification 已弃用,使用 UNUserNotificationCenter

UNUserNotificationCenter.current().requestAuthorization(options: [.alert])
{ (success, error) in
if success {
print("Permission Granted")
} else {
print("There was a problem!")
}
}


let notification = UNMutableNotificationContent()
notification.title = "title"
notification.subtitle = "subtitle"
notification.body = "the body."

let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "notification1", content: notification, trigger: notificationTrigger)

UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

关于ios - 锁屏ios上的本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49773068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com