有沒有人成功地使用iOS設備作爲使用cordova/phonegap的iBeacon進行宣傳?我已經完成了一個本地應用程序(airLocate是一個很好的演示應用程序來做到這一點)。我期待的是使用phonegap/cordova插件進行廣告宣傳。iOS - 使用Phonegap作爲iBeacon發佈
我有以下插件: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();
所以,任何人做這成功了嗎?我沒有想法,希望有人在那裏做了,至少可以讓我知道這是可能的(相對容易)。 :)
謝謝!