gpt4 book ai didi

ios - 在 iOS 上获取通知主体?

转载 作者:行者123 更新时间:2023-11-28 07:20:11 25 4
gpt4 key购买 nike

我想获取通知的正文内容/文本,并在单击操作按钮后将该文本保存在变量中。

例如,我收到通知并且有 2 个操作按钮。如果我点击其中的第一个,它会将通知的正文内容保存在名为“内容”的变量中。如果我点击第二个,它将获得通知标题并将其保存在名为“Title”的变量中。

正文和标题内容是可变的。

实例:

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == "Yes" {
//var Content = the content of the Notification
} else {
//var Title = the Title of the Notification
}

scheduleNotification()
completionHandler()
}

最佳答案

保存到用户默认值

设置数据:

 UserDefaults.standard.set("Title from notification", forKey: "TITLE")

获取数据:

let titleValue = UserDefaults.standard.value(forKey:"TITLE") as? String

如果您想在使用后重置该值,只需为同一键保留 nil 值即可。

关于ios - 在 iOS 上获取通知主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58464668/

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