有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速

Posted

技术标签:

【中文标题】有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速【英文标题】:Is there a way a widget can catch UNUserNotificationCenterDelegate? SWIFT 【发布时间】:2020-01-31 05:35:59 【问题描述】:

请帮忙

用户通知

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) 
 

【问题讨论】:

let action1 = UNNotificationAction(identifier: "tapAction1",title: "Tap me later", options: [.init(rawValue: 0)]) let action2 = UNNotificationAction(identifier: "tapAction1", title: "Tap me now", options: [.foreground]) let action3 = UNNotificationAction(identifier: "decline", title: "Decline", options: []) 请编辑您的问题并更好地描述您的问题,以便人们可以帮助您。 @Hassan,标题说明了一切......我需要小部件来捕捉推送通知操作......它只在应用程序上工作...... 【参考方案1】:

**我的回答,没有办法做到这一点..根据苹果..我认为这个问题将来可能会出现..

@available(ios 10.0, *) 打开类 UNUserNotificationCenter : NSObject

// The delegate can only be set from an application
weak open var delegate: UNUserNotificationCenterDelegate?

【讨论】:

以上是关于有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速的主要内容,如果未能解决你的问题,请参考以下文章

如何让小部件测试等到 Bloc 更新状态?

python 让小部件保持最佳状态

在 Gtk 中,是不是可以让小部件淡入淡出?

如何让 qt 设计器自定义 QOpenGLWidget 小部件背景透明?

小部件库捕获的异常

“问题加载小部件”无法以某种方式检测和处理加载错误?