【发布时间】:2016-05-18 12:15:54
【问题描述】:
有没有人成功地使用 iOS 设备使用 cordova/phonegap 来宣传 iBeacon?我已经使用本机应用程序完成了它(airLocate 是一个很好的演示应用程序)。我想做的是使用 phonegap/cordova 插件做广告。
我有以下插件:https://github.com/petermetz/cordova-plugin-ibeacon 使用这个插件,我成功地监测了信标,成功地对信标进行了测距,但我无法做广告。我使用了以下代码(来自该站点):
var uuid = '00000000-0000-0000-0000-000000000000';
var identifier = 'advertisedBeacon';
var minor = 2000;
var major = 5;
var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid, major, minor);
// The Delegate is optional
var delegate = new cordova.plugins.locationManager.Delegate();
// Event when advertising starts (there may be a short delay after the request)
// The property 'region' provides details of the broadcasting Beacon
delegate.peripheralManagerDidStartAdvertising = function(pluginResult) {
console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
};
// Event when bluetooth transmission state changes
// If 'state' is not set to BluetoothManagerStatePoweredOn when advertising cannot start
delegate.peripheralManagerDidUpdateState = function(pluginResult) {
console.log('peripheralManagerDidUpdateState: '+ pluginResult.state);
};
cordova.plugins.locationManager.setDelegate(delegate);
// Verify the platform supports transmitting as a beacon
cordova.plugins.locationManager.isAdvertisingAvailable()
.then(function(isSupported){
if (isSupported) {
cordova.plugins.locationManager.startAdvertising(beaconRegion)
.fail(console.error)
.done();
} else {
console.log("Advertising not supported");
}
})
.fail(function(e) { console.error(e); })
.done();
此代码运行成功,但不做广告。我使用了信标扫描仪,但它没有拾取它。我运行代码检查它是否是广告,但它总是返回错误:
cordova.plugins.locationManager.isAdvertising()
.then(function(isAdvertising){
console.log("isAdvertising: " + isAdvertising);
})
.fail(function(e) { console.error(e); })
.done();
我也通过以下方式征求了用户的同意:
cordova.plugins.locationManager.requestWhenInUseAuthorization();
那么,有没有人成功地做到了这一点?我没有想法,希望有人已经做到了,至少可以让我知道这是可能的(相对容易)。 :)
谢谢!
【问题讨论】: