gpt4 book ai didi

ios - 无法对推送通知自定义按钮执行操作

转载 作者:行者123 更新时间:2023-11-28 07:40:03 25 4
gpt4 key购买 nike

我正在开发一个涉及设备到设备推送通知的 iOS 应用程序。在前台和后台状态下,我能够接收通知并能够在各自的自定义按钮(接受和拒绝)中执行各自的操作。在上述两个状态下一切正常。但是在终止/终止状态下,虽然我能够收到通知,但我无法对单击自定义按钮(接受和拒绝)执行操作。你们能帮我这个吗? Notification screenshot with Custom buttons Accept and Reject

//Notification action button function
func setActionCategories(){
let acceptAction = UNNotificationAction(
identifier: NAString().notificationAcceptIdentifier(),
title: NAString().accept().capitalized,
options: [.init(rawValue: 0)])

let rejectAction = UNNotificationAction(
identifier: NAString().notificationRejectIdentifier(),
title: NAString().reject().capitalized,
options: [.init(rawValue: 0)])

let actionCategory = UNNotificationCategory(
identifier: NAString().notificationActionCategory(),
actions: [acceptAction,rejectAction],
intentIdentifiers: [],
options: [.customDismissAction])

UNUserNotificationCenter.current().setNotificationCategories(
[actionCategory])
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo

//Here we are performing Action on Notification Buttons & We created this buttons in "setActionCategories" function.
if response.notification.request.content.categoryIdentifier == NAString().notificationActionCategory() {

//Created Firebase reference to get currently invited visitor by E-Intercom
var gateNotificationRef : DatabaseReference?
gateNotificationRef = GlobalUserData.shared.getUserDataReference().child(Constants.FIREBASE_CHILD_GATE_NOTIFICATION).child(userUID).child(guestType!).child(guestUID!)

//Performing accept & reject on click of recently invited visitor by E-Intercom from Notification view.
switch response.actionIdentifier {

//If Accept button will pressed
case NAString().notificationAcceptIdentifier():
gateNotificationRef?.child(NAString().status()).setValue(NAString().accepted())
}
break

//If Reject button will pressed
case NAString().notificationRejectIdentifier(): gateNotificationRef?.child(NAString().status()).setValue(NAString().rejected())
break

default:
break
}
}
UIApplication.shared.applicationIconBadgeNumber = 0
completionHandler()
}

最佳答案

您好 Ashish 能否提供一些代码以便我们更好地帮助您。那里应该有一个完成处理程序,您可以在其中添加一个 Action 函数。然后您可以执行您需要按钮执行的任何操作。

关于ios - 无法对推送通知自定义按钮执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52531163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com