iOS - 使用 Phonegap 作为 iBeacon 做广告

iOS - Advertise as an iBeacon using Phonegap

有没有人成功使用 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();

此代码 运行s 成功,但不做广告。我使用了信标扫描仪,但它没有接收到它。我 运行 检查它是否是广告的代码,但它总是返回 false:

cordova.plugins.locationManager.isAdvertising()
.then(function(isAdvertising){
    console.log("isAdvertising: " + isAdvertising);
})
.fail(function(e) { console.error(e); })
.done();

我也通过以下方式征求了用户的同意:

cordova.plugins.locationManager.requestWhenInUseAuthorization(); 

所以,有没有人成功做到这一点?我没有想法,希望有人已经做到了并且至少可以让我知道这是可能的(相对容易)。 :)

谢谢!

所以我终于从 ibeacon 插件问题部分的某人那里得到了答案。您可以在这里看到答案 - 感谢 cgewecke 的回答:

https://github.com/petermetz/cordova-plugin-ibeacon/issues/231

但基本上,您需要在 xcode 中启用 "Location Updates"(在使用 cordova 构建它之后)。转到项目(常规设置所在的位置),然后转到 Capabilities->Background Modes->click "Location updates"。