java怎么给按钮自定义位置_如何添加按钮到自定义通知并相应地响应按钮?

我正在使用 UNNotificationContentExtension 并试图找出如何在我的视图中添加按钮并在我的扩展类中为该按钮设置IBAction?

请参阅附件图片:

ad8a81a0-6cd6-4ae9-8d29-6b08d332bb54.png

正如你所看到的,我已经为 UNNotificationContentExtension 类添加了两个按钮,但永远不会被调用?

这是我在我的app委托中设置通知的方法:

func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?) - > Bool {

let center = UNUserNotificationCenter.current()

let options: UNAuthorizationOptions = [.alert]

center.requestAuthorization(options: options) { (authorized, error) in

if authorized {

let categoryId = "com.tutplus.Custom-Notification-Interface.notification"

let category = UNNotificationCategory(identifier: categoryId, actions: [], intentIdentifiers: [], options: [])

center.setNotificationCategories([category])

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 30, repeats: false)

let content = UNMutableNotificationContent()

content.categoryIdentifier = categoryId

content.title = "Notification Title"

content.subtitle = "Notification Subtitle"

content.body = "Notification body text"

content.userInfo = ["customNumber": 100]

let request = UNNotificationRequest(identifier: "exampleNotification", content: content, trigger: trigger)

center.add(request, withCompletionHandler: nil)

}

}

return true

}

I don't want to add these to UNNotificationAction like this way :

let ok = UNNotificationAction(identifier: "OKIdentifier",

title: "Turn off", options: [.destructive])

我需要在视图中有按钮并相应地对它们做出反应 . 我很感激,如果有人可以帮助我 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值