Ionic 应用程序未检测到 iOS 上的 iBeacon(cordova-plugin-estimote)
Ionic application not detecting iBeacons on iOS (cordova-plugin-estimote)
我目前正在开发一个混合应用程序 (Ionic),但在 iOS 上检测 iBeacon 时遇到问题(目前在 9.2 上开发)。我正在使用 cordova-plugin-estimote (https://github.com/evothings/phonegap-estimotebeacons) 来检测信标,按照他们的文档进行操作,在 Android 上一切正常,但在 iOS 上却不行。根本没有检测到信标。没有错误,只是没有找到任何东西。
有趣的事实:当我在 iPhone 上下载原始的 estimote 应用程序时,它在我登录之前也没有检测到任何 iBeacons。之后,它开始正常检测它们。为什么会这样?
我的 AngularJS 代码的相关部分基于插件文档:
$scope.init = function() {
bluetoothSerial.isEnabled(scanBeacons, errorBluetooth);
}
function scanBeacons() {
startScanning();
updateList = $interval(updateView, 5000);
}
function startScanning() {
console.log("requesting permissions");
estimote.beacons.requestAlwaysAuthorization(successAuth, errorAuth);
}
function successAuth(){
console.log("success auth, starting scan");
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
}
function errorAuth(){
console.log("error auth");
popupService.showPopup("Authorization error", "Location services required to perform scanning");
}
function onMonitoringSuccess(regionState) {
console.log("monitoring success: "+JSON.stringify(regionState));
var successHandler = function (response) {
$scope.downloadedlist = response;
$scope.offline = false;
};
var errorHandler = function (response) {
$scope.beaconList = regionState.beacons;
};
eventService.getBeaconList(regionState.beacons, storageService.getEventId())
.then(successHandler)
.catch(errorHandler);
}
function onError(response) {
console.log("monitoring error: "+JSON.stringify(response));
popupService.showPopup('popup.error.title', 'popup.error.server');
}
如您所见,我有一些 console.log 语句(必须以这种方式完成)并且我得到 "requesting permissions",紧接着是 "success auth, starting scan"。这很奇怪,因为显示了授权弹出窗口,但代码不等待用户输入,它只是自动触发成功处理程序 (successAuth) 函数,仅此而已。没有更多的日志,这意味着没有监控成功,没有错误,它只是没有找到任何信标。
感谢任何帮助。谢谢
终于找到解决办法了。问题出在这里:
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
原来 Android 允许在以下函数中使用 {} 参数(这意味着查找所有区域),但 iOS 不允许。指定区域后,我的应用程序成功找到了信标。
示例:
function successAuth(){
console.log("success auth, starting scan");
var region = { uuid: 'YOUR_UUID_HERE' }
estimote.beacons.startRangingBeaconsInRegion(
region,
onMonitoringSuccess,
onError);
}
Estimote 开发者报价:
iOS only allows scanning for beacons the UUID of which you know. All Estimote Beacons ship with our default UUID, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", and these are the beacons you can see on the radar even when not logged in. If you change this UUID to something else, then you need to stay logged in so that Estimote app can know what the UUIDs of your beacons are, and scan for them in addition to the default UUID.
来源:https://forums.estimote.com/t/beacons-not-detected-using-estimote-ios-app/1580/5
这也解释了为什么 Estimote App 在登录后开始检测 iBeacons。
我目前正在开发一个混合应用程序 (Ionic),但在 iOS 上检测 iBeacon 时遇到问题(目前在 9.2 上开发)。我正在使用 cordova-plugin-estimote (https://github.com/evothings/phonegap-estimotebeacons) 来检测信标,按照他们的文档进行操作,在 Android 上一切正常,但在 iOS 上却不行。根本没有检测到信标。没有错误,只是没有找到任何东西。
有趣的事实:当我在 iPhone 上下载原始的 estimote 应用程序时,它在我登录之前也没有检测到任何 iBeacons。之后,它开始正常检测它们。为什么会这样?
我的 AngularJS 代码的相关部分基于插件文档:
$scope.init = function() {
bluetoothSerial.isEnabled(scanBeacons, errorBluetooth);
}
function scanBeacons() {
startScanning();
updateList = $interval(updateView, 5000);
}
function startScanning() {
console.log("requesting permissions");
estimote.beacons.requestAlwaysAuthorization(successAuth, errorAuth);
}
function successAuth(){
console.log("success auth, starting scan");
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
}
function errorAuth(){
console.log("error auth");
popupService.showPopup("Authorization error", "Location services required to perform scanning");
}
function onMonitoringSuccess(regionState) {
console.log("monitoring success: "+JSON.stringify(regionState));
var successHandler = function (response) {
$scope.downloadedlist = response;
$scope.offline = false;
};
var errorHandler = function (response) {
$scope.beaconList = regionState.beacons;
};
eventService.getBeaconList(regionState.beacons, storageService.getEventId())
.then(successHandler)
.catch(errorHandler);
}
function onError(response) {
console.log("monitoring error: "+JSON.stringify(response));
popupService.showPopup('popup.error.title', 'popup.error.server');
}
如您所见,我有一些 console.log 语句(必须以这种方式完成)并且我得到 "requesting permissions",紧接着是 "success auth, starting scan"。这很奇怪,因为显示了授权弹出窗口,但代码不等待用户输入,它只是自动触发成功处理程序 (successAuth) 函数,仅此而已。没有更多的日志,这意味着没有监控成功,没有错误,它只是没有找到任何信标。
感谢任何帮助。谢谢
终于找到解决办法了。问题出在这里:
estimote.beacons.startRangingBeaconsInRegion(
{},
onMonitoringSuccess,
onError);
原来 Android 允许在以下函数中使用 {} 参数(这意味着查找所有区域),但 iOS 不允许。指定区域后,我的应用程序成功找到了信标。
示例:
function successAuth(){
console.log("success auth, starting scan");
var region = { uuid: 'YOUR_UUID_HERE' }
estimote.beacons.startRangingBeaconsInRegion(
region,
onMonitoringSuccess,
onError);
}
Estimote 开发者报价:
iOS only allows scanning for beacons the UUID of which you know. All Estimote Beacons ship with our default UUID, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", and these are the beacons you can see on the radar even when not logged in. If you change this UUID to something else, then you need to stay logged in so that Estimote app can know what the UUIDs of your beacons are, and scan for them in addition to the default UUID.
来源:https://forums.estimote.com/t/beacons-not-detected-using-estimote-ios-app/1580/5
这也解释了为什么 Estimote App 在登录后开始检测 iBeacons。