如何使用 Worklight 和 Cordova 插件从混合应用程序的通知中获取数据
How to get data from notifications in hybrid app using Worklight and Cordova plugin
我正在使用 IBM MobileFirst 8.5 和 Cordova 插件编写混合应用程序,但我不知道如何从通知中获取数据。
我想创建一个列表,其中包含来自我的应用内通知的数据。是否可以使用 Cordova 或 IBM MobileFirst?我记得当我使用例如时是可能的Java 在 Android 平台上使用处理程序。
所有教程仅显示 "how to push notification" 来自我的应用程序,但我没有找到教程 "how to get data from notification within my app"。
没有这样的版本"MobileFirst 8.5"。有 6.3 或 7.0...
此外,您不会从您的应用程序发送 通知,您只能在您的应用程序中接收 通知。所有教程都会向您展示如何在您的应用中处理(显示)通知。教程附带的示例应用程序将通知的有效负载(通过通知发送的文本)放在警报中 - 但您也可以用它做任何您想做的事情。
例如,在 Hybrid 示例应用程序中有以下代码:
// Handle received notification
function pushNotificationReceived(props, payload) {
alert("pushNotificationReceived invoked");
alert("props :: " + JSON.stringify(props));
alert("payload :: " + JSON.stringify(payload));
}
不是在警报中显示通知的 props
和 payload
,而是在 table...
中简单地 take the content and put it
假设您现在 index.html 中有一个 table:
<table id="myTable">
</table>
然后在main.js中找到并插入内容:
function pushNotificationReceived(props, payload) {
$("#myTable").html(
"<tr>" + JSON.stringify(payload) + " " + JSON.stringify(props) + "</tr>");
}
这只是您 could/should 为在处理 table 中显示推送内容所做的操作的一个非常简单的摘要。您需要进一步增强它。
我正在使用 IBM MobileFirst 8.5 和 Cordova 插件编写混合应用程序,但我不知道如何从通知中获取数据。
我想创建一个列表,其中包含来自我的应用内通知的数据。是否可以使用 Cordova 或 IBM MobileFirst?我记得当我使用例如时是可能的Java 在 Android 平台上使用处理程序。
所有教程仅显示 "how to push notification" 来自我的应用程序,但我没有找到教程 "how to get data from notification within my app"。
没有这样的版本"MobileFirst 8.5"。有 6.3 或 7.0...
此外,您不会从您的应用程序发送 通知,您只能在您的应用程序中接收 通知。所有教程都会向您展示如何在您的应用中处理(显示)通知。教程附带的示例应用程序将通知的有效负载(通过通知发送的文本)放在警报中 - 但您也可以用它做任何您想做的事情。
例如,在 Hybrid 示例应用程序中有以下代码:
// Handle received notification
function pushNotificationReceived(props, payload) {
alert("pushNotificationReceived invoked");
alert("props :: " + JSON.stringify(props));
alert("payload :: " + JSON.stringify(payload));
}
不是在警报中显示通知的 props
和 payload
,而是在 table...
假设您现在 index.html 中有一个 table:
<table id="myTable">
</table>
然后在main.js中找到并插入内容:
function pushNotificationReceived(props, payload) {
$("#myTable").html(
"<tr>" + JSON.stringify(payload) + " " + JSON.stringify(props) + "</tr>");
}
这只是您 could/should 为在处理 table 中显示推送内容所做的操作的一个非常简单的摘要。您需要进一步增强它。