Interactive Notifications Handling

With the interactive notifications capability you could add multiple buttons to your messages. It's then required to handle different buttons clicks. It could be done using our message response handler.

Objective-C

[XPush registerMessageResponseHandlerWithCompletion:^(XPMessageResponse * _Nonnull x, XPMessageCompletionBlock  _Nonnull completionHandler) {
    if (response.action.type == XPActionType_Click) {
        switch (response.action.identifier) {
            // Like button which runs in background
            case "like": 
                // Like article asynchronously and call completionHandler when finished
                [self likeArticle: response.message.data[@"articleId"] completionHandler: completionHandler];
                return;

            // View button which runs in foreground
            case "view":
                // Navigate to the article page
                [self openArticle: response.message.data[@"articleId"]];
                completionHandler();
                return;
        }
    }

    // If nothing to be done
    completionHandler();
}]; 

 

Swift 3


XPush.registerContinousMessageResponseHandler({(_ response: XPMessageResponse, _ callback: XPMessageCompletionBlock) -> Void in
        if response.action.type == XPActionType_Click {
            //like button which runs in background
            if(response.action.identifier == "like"){
                likeArticle(response.message.data["articleId"])
            } 
 
            //View button which runs in foreground
            else if(response.action.identifier == "like"){
                openArticle(response.message.data["articleId"])
            }
        }
           
        //if nothing to be done
        completionHandler()
 })



Android

Implement the MessageResponseListener in your Application.java class


public class YOUR_APPLICATION_CLASS extends Application  implements MessageResponseListener {

@Override
    public void messageResponseReceived(Message messagePayload,
                                        HashMap<String, String> responsePayload,
                                        WeakReference uiReference) {

        if(responsePayload.get("responseType").equals("click")){
            switch (responsePayload.get("action")){
                // Like button which runs in background
                case "like":
                    //like article asynchronously
                    likeArticle(messagePayload.data.get("articleId"));
                    break;
                // View button which runs in foreground
                case "view":
                    //navigate to article page
                    goToArticle(uiReference, messagePayload.data.get("articleId"));
                    break;
            }
        }
    }
Have more questions? Submit a request

0 Comments

Article is closed for comments.