Ibm mobilefirst 在Worklight适配器过程中使用setTimeout
我尝试在Worklight适配器过程中使用设置超时。它不起作用Ibm mobilefirst 在Worklight适配器过程中使用setTimeout,ibm-mobilefirst,worklight-adapters,Ibm Mobilefirst,Worklight Adapters,我尝试在Worklight适配器过程中使用设置超时。它不起作用 WLSE0099E: An error occurred while invoking procedure [project BusinessBank]PushAdapter/submitNotificationFWLSE0100E: parameters: [project BusinessBank] ReferenceError: "setTimeout" is not defined. (PushAdapter-impl.
WLSE0099E: An error occurred while invoking procedure [project BusinessBank]PushAdapter/submitNotificationFWLSE0100E: parameters: [project BusinessBank]
ReferenceError: "setTimeout" is not defined. (PushAdapter-impl.js#37)
我需要在调用适配器过程后保持发送推送通知。这是演示的需要。我的代码示例:
WL.Server.createEventSource({
name: 'PushEventSource',
onDeviceSubscribe: 'deviceSubscribeFunc',
onDeviceUnsubscribe: 'deviceUnsubscribeFunc',
securityTest:'AngularStarter-strong-mobile-securityTest'
});
function deviceSubscribeFunc(userSubscription, deviceSubscription){}
function deviceUnsubscribeFunc(userSubscription, deviceSubscription){}
function submitNotification(userId, notificationText) {
var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);
if (userSubscription == null) {
return { result: "No subscription found for user :: " + userId };
}
var badgeDigit = 1,
notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom: "data"});
setTimeout(function() {
WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);
WL.Server.notifyAllDevices(userSubscription, notification);
},5000);
return {
result: "Notification sent to user :: " + userId
};
}
如果你真的是关于,如果你能添加一些代码示例,说明你到底想做什么,这会很有帮助,因为这是一个编程问答网站 如果使用Worklight Studio演示应用程序,则无需实施超时。
打开应用程序,登录,订阅通知,关闭应用程序。然后,右键单击适配器并选择运行方式>调用Worklight过程,然后在文本中添加用户名(例如:“myuser”、“mytext”)。就这样。。。将发送通知。无论何时你想要它被发送 否则,
对于适配器过程,没有设置超时这样的事情 请看这里: 要为过程设置超时,请在适配器XML文件中:
<procedure name="nameHere" requestTimeoutInSeconds="valueHere"/>
请查看和。设置超时API属于全局窗口对象。基本上,您使用它的方式是window.setTimeout()的快捷方式
由于适配器不是浏览器,而是服务器可运行代码,所以它没有全局窗口对象,所以您没有setTimeout API 我对推送演示有问题。我需要演示此Worklight功能,并希望在调用adapters过程后保留发送消息4-5秒。我需要一段时间来关闭应用程序并显示收到的推送通知。我无法在应用程序代码中设置计时器,因为适配器将不会被调用。为什么需要计时器?只需关闭应用程序,然后右键单击Worklight Studio中的适配器,然后选择运行方式>调用Worklight适配器。在这里,您可以输入用户名和消息“idan”,以及一些消息“。就是这样。我需要一个定时器来演示接收推送。对于客户来说,推送就是通知中心或锁屏上显示的内容。所以,当我展示我的演示应用程序时,一些操作会调用Push适配器过程。我需要一段时间来关闭应用程序并显示收到的通知。我无法在演示中运行笔记本电脑,打开eclipse并调用适配器过程。适配器是服务器的一部分,而不是应用程序的一部分。现在,您提到要在客户端调用过程中使用计时器吗?你需要非常清楚你到底想要什么,因为你根本不清楚。正如Anton所解释的,您不能在适配器代码中使用setTimeout。