Есть ли способ, которым виджет может перехватить UNUserNotificationCenterDelegate? СВИФТ - PullRequest
0 голосов
/ 31 января 2020

Пожалуйста, помогите

enter image description here

UserNotifications

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 Center

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent  notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
 }

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
 }

1 Ответ

0 голосов
/ 31 января 2020

** Мой ответ, нет никакого способа сделать это .. согласно яблоку .. я думаю, что этот вопрос может появиться в будущем ..

@ доступно (iOS 10.0, *) открытый класс UNUserNotificationCenter: NSObject {

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