-1

I´m working on a worklight (now mobileFirst) app ment to work on Android and iPhone. One of the issues is that i need to locate the user in some points, in order to notify him/her with a local push notification. Everything seems to work fine while the app is on foreground, but i also need it to work while on background.

i´ve checked the following links among others but nothing works for me yet:

This is my code if it helps:

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

I´m actually trying on iOS, and my info.plist file looks like this:

enter image description here

What i get is nothing while on background, but when i´m back to foreground it seems like i get everything at once. So, it looks like it actually does something, but it doesn´t let you know until you go back to foreground... is there way to keep the worklight process active while on background?

Any help will be appreciated, thanks in advance!

VaroX
  • 430
  • 4
  • 17

1 Answers1

0

So if I understand the question correctly, you are attempting to make "local notifications" but no where in the code supplied do you show how are you attempting to do that?

Anyway, local notifications are only possible via a Cordova plug-in. See here:

Community
  • 1
  • 1
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • Hi, what i am trying to do is: 1) Locate the user, in foreground and background 2) send a local notification However, i said that in order to make a complete explanation. My problem as i mentioned at the end of my question is that i´m not able to make my app locate the user in background mode. – VaroX Dec 11 '15 at 14:02
  • Are you sure you've got your local notifications set up right? Maybe check out https://stackoverflow.com/questions/16811466/local-notification-in-background to validate that your notifications are working right without the location data first. It does sound like the location data is being gathered at least ("it seems like i get everything at once"). – MotiNK Dec 11 '15 at 16:44
  • Hi, Just to make it clear, my issue is not the local notifications, it´s when the apps goes to background. @user2674117, yes, it seems like the data is being gathered while in background, but the problem is that i "don´t know that" until i get into foreground again... and my need is to know that location data is being gathered while in background in order to notify the user. Once again, DO YOU KNOW HOW TO MAKE A WORKLIGHT PROCESS ALIVE WHILE IN BACKGROUND?. thx – VaroX Dec 14 '15 at 09:03
  • Generally, once you have set up the location background key, the worklight code will run in the background when receiving location updates. You should for example be able to send events to the server while in background mode. This is speculation, but it might be that the way you are doing the local notifications is crossing thread boundaries and as a result that other thread is not executing in background. – MotiNK Dec 14 '15 at 14:37
  • yeah... it should, but it´s not! :( – VaroX Dec 14 '15 at 17:09