如何让wl.device.geo.acquireposition在后台运行

时间:2015-12-11 12:51:07

标签: ios ibm-mobilefirst worklight-geolocation mobilefirst-geolocation

我正在开发一款适用于Android和iPhone的工作灯(现在是mobileFirst)应用程序。其中一个问题是我需要在某些点找到用户,以便通过本地推送通知通知他/她。当应用程序处于前台时,一切似乎都能正常工作,但我也需要它在背景上工作。

我检查过以下链接,但对我来说没有任何作用:

如果有帮助,这是我的代码:

function getFirstPositionAndTrack() {
        // use GPS to get the user's location
        var geoPolicy = WL.Device.Geo.Profiles.LiveTracking();
        geoPolicy.timeout = 60000; // set timeout to 1 minute
        geoPolicy.maximumAge = 10000; // allow to use a position that is 10 seconds old

        // note: to see at high-accuracy, change RoughTracking above to LiveTracking

        // get the user's current position
        WL.Device.Geo.acquirePosition(
                                      function(pos) {
                                      // when we receive the position, we display it and start on-going acquisition


                                      WL.Logger.debug("acquired position");
                                      WL.Logger.debug("Longitude: " + pos.coords.longitude);
                                      WL.Logger.debug("Latitude: " + pos.coords.latitude);

                                      var triggers = new Object();
                                      triggers.Geo = {};

                                      var trigger_events = generateTrigger();
                                      triggers.Geo = trigger_events;


                                      WL.Device.startAcquisition({ Geo: geoPolicy }, triggers, { Geo: alertOnGeoAcquisitionErr } );



                                      },
                                      function(geoErr) {
                                      alertOnGeoAcquisitionErr(geoErr);
                                      },
                                      geoPolicy
                                      );
        }


        //Method that create triggers dinamically

        function generateTrigger() {



        var trigger_events = new Object();

        angular.forEach(json.locations, function(location) {
                        var trigger = {
                        type: "DwellInside",
                        circle: {
                        longitude: location.longitude,
                        latitude: location.latitude,
                        radius: 100
                        },
                        dwellingTime: 3000,
                        callback: function() {
                        //                WL.Logger.info("Enter branch");
                        //                WL.Client.transmitEvent({ branch: "enter branch"}, true);

                        console.log("Location: "+JSON.stringify(location));
                        alert("We are in: "+location.name);
                        }
                        };
                        trigger_events["dwellArea_"+location.name] = trigger;
                        });

        return trigger_events;
        }

我实际上在iOS上尝试,我的info.plist文件如下所示:

enter image description here

在背景上我得到的是什么,但是当我回到前景时,我似乎立刻得到了所有东西。所以,看起来它实际上做了一些事情,但它不会让你知道,直到你回到前台...是否有办法在后台保持工作灯处理活动?

任何帮助将不胜感激,提前谢谢!

1 个答案:

答案 0 :(得分:0)

因此,如果我正确理解了这个问题,那么您正在尝试制作“本地通知”,但是在提供的代码中没有显示您是如何尝试这样做的?

无论如何,只能通过Cordova插件进行本地通知。见这里:

相关问题