1
私のアプリケーションのためのリモート通知を設定し、それは次のように動作します。 ユーザーが通知の本文をタップすると、関数が呼び出されます(ユーザーが特定のViewControllerに移動します)。 しかし、ユーザがアクションボタンの1つをタップすると、ボタンのアクションはボディタップアクションと同じように実行されます。どのようにして、アクションボタンは、そのアクションだけを実行することなく、そのアクションを実行することができます。ここでAppleプッシュ通知アクションボタン
は私のサンプルコードです:
@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"アクションとは何ですか?私は上記のコードでそれを見ることはできません。私は受け入れると拒否を参照してください。 – matiastofteby
ボディアクションをトリガーするコードは 'didReceive response'です。解析コードは、本体がタップされたときに動作するSWRevealの関数を実行します。ユーザーがアクションボタンをタップすると、その動作を無効にします。 – Tarek