ios - 如何创建警报通知 Swift iOS?
问题描述
我想当用户从 fcm(Firebase 云消息传递)或调度程序本地通知(如警报通知)收到通知时,如下图所示:
这是我的代码:
func onTest() {
let content = UNMutableNotificationContent()
content.title = "Weekly Staff Meeting"
content.body = "Every Tuesday at 2pm"
// Configure the recurring date.
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
dateComponents.hour = 16 // 14:00 hours
dateComponents.minute = 11
// Create the trigger as a repeating event.
let trigger = UNCalendarNotificationTrigger(
dateMatching: dateComponents, repeats: true)
// Create the request
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
}
}
}
我现在的代码就像在 5 秒内消失的通常通知一样,我想让它像警报通知或 Whatsapp 呼叫通知一样。请帮忙谢谢。
解决方案
由于 Apple 的限制,app dev 最多只能播放 30 秒的通知音。如果您的提示音超过 30 秒,它将播放默认通知音。
如果您的通知音在 5 秒后消失,请尝试将通知呈现选项设置为列表、徽章和声音。一旦没有通知横幅,您的 30 秒提示音将一直播放到结束。
不幸的是,没有合法的方法或任何解决方法可以让通知响铃连续响起,例如闹钟。希望我错了。
https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions
推荐阅读
- java - 如何将文本文件中的值存储到java中的数组中
- python - 从多个(连续一天)URL 下载多个(连续)txt
- csv - 如何在不同列中分隔逗号分隔值,同时在 Google 表格的其余行中保留值?
- html - 设置背景图像的最大高度,但具有水平覆盖
- node.js - 如何使用nodejs创建谷歌表格文档
- r - anaconda命令窗口中的Rstudio和R具有不同的环境
- visual-studio-code - Visual Studio Code 为文本编辑器导航配置分词
- python - 如何使用 numba.njit 运行成员函数
- r - 如果我只知道每个值的一部分,则用 NA 替换值的子集
- python - 如何在 django 应用程序中制作可点击的锚文本?