対話式通知

improve this page | report issue

概説

対話式通知を使用すると、ユーザーは、通知が到着したときに、アプリケーションを開かなくてもアクションを実行できます。 対話式通知を受信すると、デバイスは通知メッセージとともにアクション・ボタンを表示します。

対話式通知は、iOS バージョン 8 以降および Android v7.0 (API レベル 24) 以降のデバイスでサポートされています。 以前のバージョンの iOS デバイスまたは Android デバイスに対話式通知が送信された場合、通知アクションは表示されません。

対話式プッシュ通知の送信

通知を準備して送信します。 詳しくは、プッシュ通知の送信を参照してください。

対話式通知は、通知アクションと通知アクションのカテゴリーへのグループ化を中心としています。 まず、アプリケーション・ユーザーに提供できるさまざまな通知アクションを定義します。 次に、各カテゴリーが 1 つ以上の通知アクションをグループにするカテゴリーを定義します。 最も重要なこととして、各カテゴリーに固有 ID を割り当てます。 次に、対話式プッシュ通知を iOS デバイスに送信するために、MobileFirst Operations Console → 「[ご使用のアプリケーション]」 → 「プッシュ」 → 「通知の送信」 → 「iOS カスタム設定」またはMobileFirst Operations Console → 「[ご使用のアプリケーション]」 → 「プッシュ」 → 「通知の送信」 → 「Android カスタム設定」、あるいは両方の下で、カテゴリー ID を指定します。そのカテゴリー ID に基づいて、モバイル・デバイスに通知アクションのボタンが表示されます。 例えば、次のとおりです。

MobileFirst Operations Console

Android デバイスに対話式通知を送信するには、MobileFirst Operations Console → 「[ご使用のアプリケーション]」 → 「プッシュ」 → 「通知の送信」 → 「Android カスタム設定」の下で、対話式カテゴリー ID を指定します。 例えば、次のとおりです。

MobileFirst Operations Console

Cordova アプリケーションでの対話式プッシュ通知の処理

対話式通知を受信するには、以下の手順を実行します。

  1. メインの JavaScript 内で、対話式通知用に登録済みのカテゴリーを定義し、それをデバイス登録呼び出し MFPPush.registerDevice に渡します。

    var options = {
         ios: {
             alert: true,
             badge: true,
             sound: true,
             categories: [{
                 //Category identifier, this is used while sending the notification.
                 id : "poll", 
    
                 //Optional array of actions to show the action buttons along with the message.    
                 actions: [{
                     //Action identifier
                     id: "poll_ok", 
    
                     //Action title to be displayed as part of the notification button.
                     title: "OK", 
    
                     //Optional mode to run the action in foreground or background. 1-foreground. 0-background. Default is foreground.
                     mode: 1,  
    
                     //Optional property to mark the action button in red color. Default is false.
                     destructive: false,
    
                     //Optional property to set if authentication is required or not before running the action.(Screen lock).
                     //For foreground, this property is always true.
                     authenticationRequired: true
                 },
                 {
                     id: "poll_nok",
                     title: "NOK",
                     mode: 1,
                     destructive: false,
                     authenticationRequired: true
                 }],
                        
                 //Optional list of actions that is needed to show in the case alert.
                 //If it is not specified, then the first four actions will be shown.
                 defaultContextActions: ['poll_ok','poll_nok'],
    
                 //Optional list of actions that is needed to show in the notification center, lock screen.
                 //If it is not specified, then the first two actions will be shown.
                 minimalContextActions: ['poll_ok','poll_nok'] 
             }]     
         }
    }
    
  2. プッシュ通知のデバイスを登録する際に、options オブジェクトを渡します。

    MFPPush.registerDevice(options, function(successResponse) {
      		navigator.notification.alert("Successfully registered");
      		enableButtons();
    });  
    

ネイティブ iOS アプリケーションでの対話式プッシュ通知の処理

以下のステップに従って、対話式通知を受け取ります。

  1. リモート通知の受信時にバックグラウンド・タスクを実行するアプリケーション機能を使用可能にします。 このステップは、アクションの一部がバックグラウンド対応の場合に必要です。
  2. 対話式通知用に登録済みのカテゴリーを定義し、それをオプションとして MFPPush.registerDevice に渡します。

    //define categories for Interactive Push
    let acceptAction = UIMutableUserNotificationAction()
    acceptAction.identifier = "OK"
    acceptAction.title = "OK"
    acceptAction.activationMode = .Foreground
    
    let rejetAction = UIMutableUserNotificationAction()
    rejetAction.identifier = "Cancel"
    rejetAction.title = "Cancel"
    rejetAction.activationMode = .Foreground
    
    let category = UIMutableUserNotificationCategory()
    category.identifier = "poll"
    category.setActions([acceptAction, rejetAction], forContext: .Default)
    
    let categories:Set<UIUserNotificationCategory> = [category]
    
    let options = ["alert":true, "badge":true, "sound":true, "categories": categories]
    
    // Register device
     MFPPush.sharedInstance().registerDevice(options as [NSObject : AnyObject], completionHandler: {(response: WLResponse!, error: NSError!) -> Void in
    
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on November 27, 2019