系统是否会加载通知服务扩展并在iOS 10中调用其
如果是,我们该如何实现?
didReceive(_:withContentHandler:)
以处理本地通知?如果是,我们该如何实现?
didReceive(_:withContentHandler:)
以处理本地通知?不可以。被接受的答案描述了通知内容扩展,允许你在展开的通知视图中呈现一个ViewController,并且适用于远程和本地通知。
通知服务扩展允许你更改通知的内容(附加图片等),但不支持本地通知。不过,你可以在显示本地通知的过程中附加图片。
NotificationViewController:在这里,您可以设计自己的自定义界面并实现响应。
MainStoryboard:您可以使用此文件设计自定义通知。
Info.plist
let category = UNNotificationCategory(identifier: "myNotificationCategory", actions: [], intentIdentifiers:[], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
content.categoryIdentifier = "myNotificationCategory"
func didReceive(_ notification: UNNotification) {
//change properties of notification here.
}
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
//implement response logic here.
}
本地通知也支持通知扩展。这里明确提到了。
UNNotificationContentExtension 一个为已发送的本地或远程通知呈现自定义界面的对象。