系统会加载通知服务扩展并didReceive(_:withContentHandler:)
在iOS 10中调用它以获取本地通知吗?如果是,我们怎么做?
notifications uilocalnotification swift ios10 serviceextension
TL;DR:是否可以在不使用APNS
(或替代推送通知服务)的情况下获得重复的随机本地通知?
我正在构建一个Core Data
包含一堆对象的应用程序。(我们将它们称为小部件。)每天的某个时间(假设是中午)我想发送一条通知以查看其中一个小部件。
在didFinishLaunchingWithOptions
我中检查以确保通知已启用并设置委托等,然后调用函数来构建本地通知。所有这一切都运行良好。
var date = DateComponents()
date.hour = 12
date.minute = 00
let content = UNMutableNotificationContent()
content.title = "You should see this widget!"
content.userInfo = ["widgetID": widget.id]
content.body = "Today's Widget:\n\(widget.title!)"
content.sound = UNNotificationSound.default()
let trigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
let request = UNNotificationRequest(identifier: notificationIdentifer, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error : Error?) in if let theError = error { print(theError.localizedDescription)}}
Run Code Online (Sandbox Code Playgroud)
我的委托处理程序也正常工作:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse, …
Run Code Online (Sandbox Code Playgroud) notifications apple-push-notifications swift unusernotificationcenter unnotificationtrigger