【发布时间】:2018-09-27 06:55:51
【问题描述】:
我正在开发一个涉及设备到设备推送通知的 iOS 应用程序。在前景和背景状态下,我能够接收通知并能够在各自的自定义按钮(接受和拒绝)中执行各自的操作。在提到的两个状态下一切正常。但是在终止/终止状态下,虽然我能够收到通知,但我无法在单击自定义按钮(接受和拒绝)时执行操作。你们能帮帮我吗?
//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()
}
【问题讨论】:
-
在我的情况下,我在杀死状态下没有收到通知?你是怎么做到的?我在我的有效负载中设置了 content-available :1 。虽然它没有在杀死状态下显示通知。
-
你能告诉我你的有效载荷吗?
-
我也面临同样的挑战?你解决了吗?
标签: ios swift xcode firebase push-notification