swift - 有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速
问题描述
请帮忙
用户通知
Import UserNotifications
把它放在 viewDidLoad
func setupNotif() {
UNUserNotificationCenter.current().requestAuthorization(options [.alert,.sound]) {
(granted, error) in
}
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Push Invitation"
notificationContent.subtitle = "Push subtitle"
notificationContent.body = "Please check notif"
notificationContent.sound = .default
notificationContent.categoryIdentifier = categoryIdentifier
let notificationTrigger = UNTimeIntervalNotificationTrigger.init(timeInterval: timeInterval, repeats: false)
let notificationRequest = UNNotificationRequest.init(identifier: "SampleNotif", content: notificationContent, trigger: notificationTrigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(notificationRequest) {(error) in if (error != nil) {} else { }}
}
这是 UUNotification 中心的代表
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
解决方案
**我的回答,没有办法做到这一点..根据苹果..我认为这个问题将来可能会出现..
@available(iOS 10.0, *) 开放类 UNUserNotificationCenter : NSObject {
// The delegate can only be set from an application
weak open var delegate: UNUserNotificationCenterDelegate?
推荐阅读
- c# - Winforms中没有数据库的RDLC报告
- url - Keycloak Admin API 中“< string > array(csv)”模式的查询格式是什么?
- c# - 如何高效生成List
基于自定义模式? - node.js - 节点找不到绑定文件
- javascript - 如何让赛普拉斯包含返回布尔值而不是测试失败
- office-js - 清单中的语言覆盖不起作用
- angular - 当我在 Android 模拟器上运行构建时,Ionic App 在登录后崩溃
- macos - Mac vscode:使用 ctrl + 鼠标单击的多行
- javascript - 如何在firebase中从一个集合访问另一个集合
- jmeter - 当 jmeter 等待先前的响应发送新请求时,如何在 jmeter 中表示现实世界?