1
我爲我的應用程序設置了遠程通知,它的工作原理如下。 如果用戶點擊通知的正文,它會調用一個函數(將用戶帶到特定的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])}
你的「身體」動作是什麼?我在上面的代碼中看不到它。我只看到接受和拒絕。 – matiastofteby
觸發主體操作的代碼位於'didReceive響應'中。解析代碼在SWReveal中執行一個函數,這在輕敲正文時非常有效。如果用戶點擊操作按鈕,我想禁用該行爲。 – Tarek