【发布时间】:2019-02-18 11:34:11
【问题描述】:
它可能与问题重复 - Repeating local notification daily at a set time with swift 但 UILocalNotifications 已被 iOS 10 弃用
我正在开发闹钟应用程序,我需要两件事 1.一次本地通知 2. 间隔一段时间后重复
/// Code used to set notification
let content = UNMutableNotificationContent()
content.body = NSString.localizedUserNotificationString(forKey: titleOfNotification, arguments: nil)
content.userInfo=[]
工作正常的代码在准确的时间点击通知
/* ---> Working Fine --> how i can repeat this after 60 second if untouched
let triggerDaily = Calendar.current.dateComponents([.hour,.minute,], from: dates)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: weekdays.isEmpty == true ? false : true)
*/
/// ---> Making it Repeat After Time - How Time is passed here ?
let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 60, repeats: true)
/// ---> Adding Request
let request = UNNotificationRequest(identifier:dateOfNotification, content: content, trigger: trigger) UNUserNotificationCenter.current().add(request){(error) in
if (error != nil){
print(error?.localizedDescription ?? "Nahi pta")
} else {
semaphore.signal()
print("Successfully Done")
}
}
我怎样才能同时实现这两件事?
【问题讨论】:
-
UILocalNotification 已弃用
标签: swift uilocalnotification unnotificationrequest