gpt4 book ai didi

ios - swift 4 : Set local notification once

转载 作者:行者123 更新时间:2023-11-30 11:58:20 26 4
gpt4 key购买 nike

我想设置特定时间的本地通知,但我对此有所顾虑。例如,当我设置了一次本地通知,我说我安排了它,然后用户的手机突然关机,会发生什么情况?我确信此通知数据仅在内存中可用,并且当用户的手机关闭时它会消失。

而且我知道每次我设置相同的日期时,我都会在那时收到更多通知。我只想要一个通知,但正如我告诉过你的,我不知道如何处理用户的可能性。

这是我的示例代码:

func scheduleNotification(inSeconds : TimeInterval, completion : @escaping (_ Success : Bool) -> ()){
let notif = UNMutableNotificationContent()
notif.title = "New notification"
notif.subtitle = "Cool!"
notif.body = "I liked it!!!!"

let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: inSeconds, repeats: false)
let request = UNNotificationRequest(identifier: "myNotification", content: notif, trigger: notifTrigger)

UNUserNotificationCenter.current().add(request) { (error) in
if error != nil{
print(error!)
completion(false)
}else{
completion(true)
}
}
}

最佳答案

本地通知在 session 之间存储。我只是通过设置一个然后关闭然后打开手机来测试它。通知仍然出现。当然,如果您的手机处于关机状态,您将不会收到通知。

关于ios - swift 4 : Set local notification once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47540773/

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