2014-09-01 58 views

回答

2

如果你将在sample Worklight project for Push Notifications看看,你可以看到下面的常见\ JS \ main.js:

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

这个函数告诉显示3个警报的应用程序,告诉我们:

  • 推送通知接收
  • 其道具
  • 其有效载荷

除了上述内容外,您还可以 - 根据您的应用中多页导航的方法 - 导航到另一个“页面”。

你可以看看:


这里是一个小例子。
这些都是我做的推送通知示例项目修改:

共同\ CSS \ main.css的
增加了successfulPush ID

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

共同\ index.html在
增加了额外的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> 

共同\ JS \ main.js
修改了以下功能:

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) 
    ); 
} 

另外结合 '返回' 按钮在wlCommonInit

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

最终结果
后一推送被接收,你点击通知栏中的通知,应用程序打开,你会看到successPush DIV。你有一个按钮可以让你回到AppBody DIV。工作得很好。

如上所述,这只是一种可能的方法。你可以做任何你想做的...
enter image description here

+0

我觉得这个函数一旦收到通知就立即调用?但是我只想在用户点击通知时打开一个新页面。 – AWSSET 2014-09-02 01:10:47

+0

我试过这个,它不会在点击通知时调用这个函数。将再次尝试。谢谢。 – AWSSET 2014-09-02 03:40:03

+0

@AWSSET,这工作得很好。看到我的更新答案为一个小例子。 – 2014-09-02 04:27:51