我做了什么: - 嗨,当应用程序处于非活动状态时,我尝试在后台搜索信标,我也提到了一个链接" nraboy / ng-cordova -beacon#4 "
以下代码 startMonitoringForRegion 不会调用" didEnterRegion "和" didExitRegion "。
请帮助我如何进行背景搜索或监控
我的代码段: -
.controller("ExampleController", function($scope, $rootScope, $ionicPlatform, $cordovaBeacon) {
console.log("start")
console.log($cordovaBeacon)
$scope.beacons = {};
$ionicPlatform.ready(function() {
$cordovaBeacon.requestAlwaysAuthorization();
$rootScope.$on("$cordovaBeacon:didEnterRegion", function(event, pluginResult) {
var uniqueBeaconKey;
for(var i = 0; i < pluginResult.beacons.length; i++) {
uniqueBeaconKey = pluginResult.beacons[i].uuid + ":" + pluginResult.beacons[i].major + ":" + pluginResult.beacons[i].minor;
$scope.beacons[uniqueBeaconKey] = pluginResult.beacons[i];
console.log("ibeacon elements")
console.log(pluginResult.beacons)
}
$scope.$apply();
});
$rootScope.$on("$cordovaBeacon:didExitRegion", function(event, pluginResult) {
console.log("ibeacondidExitRegion")
// $cordovaVibration.vibrate(500);
});
$cordovaBeacon.startMonitoringForRegion($cordovaBeacon.createBeaconRegion("estimote", "uuid"));
//
});
});
前景工作: -
我的代码段: -
.controller("ExampleController", function($scope, $rootScope, $ionicPlatform, $cordovaBeacon) {
$scope.beacons = {};
$ionicPlatform.ready(function() {
$cordovaBeacon.requestWhenInUseAuthorization();
$rootScope.$on("$cordovaBeacon:didRangeBeaconsInRegion", function(event, pluginResult) {
var uniqueBeaconKey;
for(var i = 0; i < pluginResult.beacons.length; i++) {
uniqueBeaconKey = pluginResult.beacons[i].uuid + ":" + pluginResult.beacons[i].major + ":" + pluginResult.beacons[i].minor;
$scope.beacons[uniqueBeaconKey] = pluginResult.beacons[i];
}
$scope.$apply();
});
$cordovaBeacon.startRangingBeaconsInRegion($cordovaBeacon.createBeaconRegion("estimote", "8A458198-34AE-11E6-AC61-9E71128CAE77"));
});
});
我刚刚改变了#34; startRangingBeaconsInRegion&#34; to&#34; startMonitoringForRegion&#34;