Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

ibm mobilefirst - Creating customized push notification in Worklight

is there a way to direct the user to another html page upon opening a push notification?

Thank you in advanced.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you will take a look at the sample Worklight project for Push Notifications, you can see the following in commonjsmain.js:

function pushNotificationReceived(props, payload) {
    alert("pushNotificationReceived invoked");
    alert("props :: " + JSON.stringify(props));
    alert("payload :: " + JSON.stringify(payload));
}

This function tells the application to display 3 alerts, telling us that:

  • a push notification was received
  • its props
  • its payload

Instead of the above, or in addition, you could - depending on your method of multi-page navigation in your app - to navigate to another "page".

You can take a look at:


Here is a small example.
These are the modifications I did to the Push Notifications sample project:

commoncssmain.css
Added a successfulPush ID

#AppBody, #AuthBody, #successfulPush {
    margin: 0 auto;
    background-color: #ccc;
    overflow: hidden;
    overflow-y: auto;
}

commonindex.html
Added an additional DIV:

<div id="successfulPush" style="display:none">
    <div class="wrapper">
        <h2>Notification received</h2>
        <button id="back" >back to application</button>
        <p id="pushContents"></p>
    </div>  
</div>

commonjsmain.js
Modified the following function:

function pushNotificationReceived(props, payload) {     
    $("#AppBody").hide();
    $("#successfulPush").show();
    $("#pushContents").html(
        "<b>Notification contents:</b><br>" +
         "<b>Payload:</b> " + JSON.stringify(payload) + "<br>" + 
         "<b>Props:</b> " + JSON.stringify(props)
    );
}

Also binding the 'back' button in wlCommonInit:

$("#back").bind("click", function() {
    $("#successfulPush").hide();
    $("#AppBody").show();
});

The end result
After a push is received and you tap the notification in the notification bar, the app opens and you see the successfulPush DIV. There you have a button to return you to the AppBody DIV. Works just fine.

As explained, this is only one possible approach. You can do whatever you want...
enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...