IBM MobileFirst 7.0 - 使用触发器概念

时间:2015-12-08 11:16:24

标签: android triggers ibm-mobilefirst mobilefirst-geolocation

我们可以使用IBM Mobilefirst中的触发器调用Http Adapters。

我正在开发基于位置的服务和推送通知集成部分,例如当使用进入Geofench区域时,我们需要调用推送适配器向移动设备发送通知。

Geofenche代码:

dwellArea: { // alert when we have stayed in the vicinity for 3 seconds
                        type: "DwellInside",
                        circle: {
                            longitude: pos.coords.longitude,
                            latitude: pos.coords.latitude,
                            radius: 50
                        },
                        dwellingTime: 3000,
                        callback: function() {
                            alert('Still in the vicinity');

这里我们可以调用Http Adapter调用,即push Adapter见下文:

                            WL.Client.transmitEvent({ event: 'dwell inside area'}, true);
                        }
                    }

推送通知代码:

var invocationData = {adapter : "PushAdapter",
                                       procedure : "submitNotification",
                                       parameters : [ "Vinod", "Hello This is Push notification" ]
                                     };
                            var options = {
                                    onSuccess : onGetAccountsSuccess,
                                    onFailure : onGetAccountsFailed,
                                    timeout : 30000
                                };
                            WL.Client.invokeProcedure(invocationData, options);

我们可以直接在Geofench编码的回调中直接调用此推送通知代码,还是有替代解决方案。

参考链接:

地理fench: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/advanced-topics/location-services-hybrid-applications/

Pushnotification: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/notifications/push-notifications-hybrid-applications/#whatIsPushNotifications

2 个答案:

答案 0 :(得分:1)

我不清楚这个问题......为什么不创建像

这样的东西
function sendNotification() {
   // your push code...
}

而不是alert()使用sendNotification();
你试过了吗?

答案 1 :(得分:1)

这里有不同的选择。如果您要做的只是传输事件,那么您不需要声明回调。您只需在触发器定义中添加一个事件即可;例如:

      eventToTransmit: { 
         event: { 
            field1: "data1",
            field2: ["data2", "data3"]
         },
         transmitImmediately: true 
      }

请注意,这将尝试立即传输事件(以及任何以前未传输的事件)。如果您有动态数据,则需要回调并使用WL.Client.transmitEvent API。在这两种情况下,如果存在通信问题,它将根据event transmission policy重试。您将在服务器端适配器中处理该事件。请注意,使用事件可以在服务器端单独更新逻辑,而无需更新客户端逻辑。您还可以处理来自多个不同适配器的事件,而无需彼此进行调用。

或者,您可以执行调用以调用适配器中的过程。在这种情况下,如果存在任何通信问题,则需要声明失败处理程序并在那里实现任何重试逻辑。

相关问题