【发布时间】:2017-09-18 15:54:20
【问题描述】:
我为我的应用设置了远程通知,它的工作原理如下。 如果用户点击通知的正文,它会调用一个函数(将用户带到特定的 ViewController)。 然而,当用户点击其中一个动作按钮时,按钮的动作与身体点击动作一样被执行。我怎样才能让动作按钮只执行它的动作,而不让身体也执行它的动作。
这是我的代码示例:
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert,.sound,.badge])
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo as! [String:AnyHashable]
// parse userInfo and execute a function in SWReveal to show the appropriate ViewController
let action = response.actionIdentifier
if action == "acceptFriendRequest" {
print("Friend Request Accepted")
}
}
func setCategories() {
if #available(iOS 10.0, *) {
let acceptFriendRequest = UNNotificationAction(
identifier: "acceptFriendRequest",
title: "Accept",
options: [])
let rejectFriendRequest = UNNotificationAction(identifier: "rejectFriendRequest", title: "Reject", options: [.destructive])
let FrReq = UNNotificationCategory(
identifier: "FrReq",
actions: [acceptFriendRequest, rejectFriendRequest],
intentIdentifiers: [],
options: [.customDismissAction])}
【问题讨论】:
-
你的“身体”动作是什么?我在上面的代码中看不到它。我只看到接受和拒绝。
-
触发body动作的代码在
didReceive response中。解析代码在 SWReveal 中执行一个函数,当身体被点击时它几乎可以工作。如果用户点击操作按钮,我想禁用该行为。
标签: ios swift push-notification apple-push-notifications