Vin*_*ose 7 notifications uilocalnotification swift ios10 serviceextension
系统会加载通知服务扩展并didReceive(_:withContentHandler:)
在iOS 10中调用它以获取本地通知吗?如果是,我们怎么做?
否.接受的答案描述了通知内容扩展,它允许您在展开的通知视图中呈现ViewController,并使用远程和本地通知.
通知服务扩展,允许您更改通知的内容(附加图像等)不适用于本地通知.但是,您可以将图像作为过程的一部分附加,以显示本地通知.
您需要创建一个通知内容扩展来使用 iOS10 显示自定义通知。在 Xcode 菜单栏中,转到“文件”->“新建”->“目标”。然后从列表中选择通知内容扩展。
输入相应的详细信息并单击芬兰语。您将看到一个带有您的扩展名称的新文件夹。在该文件夹中,将有3个文件:
NotificationViewController :在这里您可以设计自定义界面并实现响应。
MainStoryboard :您可以使用它来设计自定义通知。
信息表
这将是您在安排通知时将在主项目中使用的类别标识符。
let category = UNNotificationCategory(identifier: "myNotificationCategory", actions: [], intentIdentifiers:[], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
content.categoryIdentifier = "myNotificationCategory"
Run Code Online (Sandbox Code Playgroud)
您的NotificationViewController 类应该如下所示。
func didReceive(_ notification: UNNotification) {
//change properties of notification here.
}
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
//implement response logic here.
}
Run Code Online (Sandbox Code Playgroud)
网上有一些很好的教程。您可以在这里、这里和这里查看。希望这可以帮助。