[英]How can I set the Local notification which fire every seconds after first set notification?
我想要的是,我將本地通知設置為上午 7:00,當它立即觸發時,通知會不斷發出,直到用戶不對通知執行任何操作或打開應用程序。
下面是第一次發送通知的代碼
let alarmNotification: UNMutableNotificationContent = UNMutableNotificationContent()
alarmNotification.title = "Demo"
alarmNotification.body = "Test"
alarmNotification.categoryIdentifier = "myDemoCategory"
let now = Date()
let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let request = UNNotificationRequest(identifier: "TestNotification\(now)", content: alarmNotification, trigger: trigger)
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print("Uh oh! We had an error: \(error)")
}
}
請建議持續發送本地通知。
謝謝
在日期組件中,在此處添加秒
let triggerWeekly = Calendar.current.dateComponents([.weekday,.hour,.minute], from: now)
通過增加秒數來設置每秒要循環播放的通知數,在iOS中最大為64。
輕按通知時,關閉所有通知並在下次重置。
如何設置本地通知,在第一次設置通知(如“Alarmy”應用程序)后每秒鍾觸發一次,而應用程序被殺死?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.