【问题标题】:Is there a way a widget can catch UNUserNotificationCenterDelegate? SWIFT有没有办法让小部件捕获 UNUserNotificationCenterDelegate?迅速
【发布时间】: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,标题说明了一切......我需要小部件来捕捉推送通知操作......它只在应用程序上工作......

标签: swift push-notification widget


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2011-04-20
    • 2017-04-27
    • 2021-09-27
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 2018-06-21
    相关资源
    最近更新 更多