【发布时间】:2021-02-24 09:23:11
【问题描述】:
当用户从 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 呼叫通知一样。请帮忙谢谢。
【问题讨论】:
标签: ios swift push-notification notifications alarm