我正在开发一个适用于 Android 和 iPhone 的工作灯(现在是 mobileFirst)应用程序。问题之一是我需要在某些点找到用户,以便通过本地推送通知通知他/她。当应用程序在前台时,一切似乎都工作正常,但我也需要它在后台工作。
我已经检查了以下链接,但还没有对我有用:
- https://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.dev.doc/devref/t_keeping_app_running_in_background.html
- https://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.0.0/com.ibm.worklight.help.doc/apiref/r_wl_location_geoAcquirePosition.html
如果有帮助,这是我的代码:
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 文件如下所示:
我在后台得到的什么都没有,但是当我回到前台时,似乎我一下子得到了一切。所以,看起来它实际上做了一些事情,但直到你回到前台才让你知道......有没有办法在后台保持工作灯进程处于活动状态?
任何帮助将不胜感激,在此先感谢!