【问题标题】:Unable to view action button for iOS 10 local notification无法查看 iOS 10 本地通知的操作按钮
【发布时间】:2016-07-21 07:54:16
【问题描述】:

我目前在 iOS 10 上查看时间间隔通知上的操作按钮时遇到问题。我创建了两个 UNNotificationAction 对象“OK”和“Cancel”添加为通知类别。

我在模拟器上收到通知,但没有任何操作按钮。下面是我的代码。

let ok = UNNotificationAction(identifier: "OKIdentifier",
                                      title: "OK", options: [])

let cancel = UNNotificationAction(identifier: "CancelIdentifier",
                                  title: "Cancel",
                                  options: [])

let category = UNNotificationCategory(identifier: "message",
                                      actions: [ok, cancel],
                                      minimalActions: [ok, cancel],
                                      intentIdentifiers: [],
                                      options: [])

UNUserNotificationCenter.current().setNotificationCategories([category!])

let content = UNMutableNotificationContent()
content.title = contentTitle
content.subtitle = contentSubtitle
content.body = contentBody

let model: TimeIntervalNotificationModel = notificationsModel as!  TimeIntervalNotificationModel

trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: model.timeInterval!, repeats: notificationsModel.repeats) as UNTimeIntervalNotificationTrigger

let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in
                if (error != nil){
                    //handle here
         print("Error: Adding notification failed:\(error?.description)")

         self.delegate?.didFailToAddNotification(error: error!)
                }
            }

【问题讨论】:

  • 你添加 UNNotificationContentExtension 吗?
  • 不确定UNNotificationAction 但在警报中您需要使用alert.addAction(ok) 实际添加按钮,这不一样吗?

标签: swift notifications ios10 unusernotificationcenter


【解决方案1】:

解决了这个问题。忘记设置通知内容的类别标识符属性。

content.categoryIdentifier = "message"

定义:

应用程序定义的类别对象的标识符指定类别标识符以创建可操作的通知。该标识符必须属于您之前在应用中注册的 UNNotificationCategory 对象。当通知传递给用户时,系统会酌情将该类别对象中定义的操作添加到通知界面。

【讨论】:

  • 你能看看这个问题吗? stackoverflow.com/questions/41740193/…
  • @GaneshKumar 你就是男人!就是这样。谈论糟糕的 UI/UX。用户是否知道他们可以做到这一点???
  • @NYCTechEngineer 很高兴它有帮助.. 如果我的问题对你有帮助,你可以投票 :)
猜你喜欢
  • 2012-06-16
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 2020-06-09
  • 2023-03-18
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多