ios - 在 Swift 中请求时具有未知内容的本地通知
问题描述
我正在寻找创建一个本地通知系统,它显示的文本与它在请求时包含的文本不同。我不想修改标准标题、正文格式的通知。为了测试这一点,我尝试创建一个显示当前日期的通知,但是当它显示时,显示的时间是两分钟前。是否可以在没有推送通知的情况下让此通知显示当前日期和时间(或其他可变内容)?
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy MM dd HH mm ss"
let dateString = dateFormatter.string(from: date)
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "the date is \(date)"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120, repeats: false)
let request = UNNotificationRequest(identifier: "TestIdentifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
解决方案
推荐阅读
- c - &A[1] 应该与 A 本身的地址相同吗?
- python - 从 python 启动后台 shell 脚本
- javascript - 当部分高于屏幕高度时如何临时禁用“滚动”
- kaldi - Kaldi的TDNN和LSTM的相关论文有哪些?
- android - 提交到Play商店后应用程序无法正常工作
- ajax - 如何抓取 AJAX 页面中的所有 url?
- r - 使用 `case_when` 和 `str_split` 的组合来改变数据框中的列
- angular - 像我们使用 jquery 或 vanilla javascript 那样在 Angular 6 中进行 dom 操作的最佳方法是什么
- objective-c - 在 Objective-C 中使用单例保留循环
- powershell - New-AzureADMSInvitation 仅适用于尚未受邀的用户