petermetz / cordova-plugin-ibeacon

An iBeacon plugin for Phonegap / Cordova 3.x and upwards. Supports both iOS and Android (contributions are welcome)
Apache License 2.0
726 stars 373 forks source link

Advertising doesn't work in background iOS #404

Open jarekskuder opened 5 years ago

jarekskuder commented 5 years ago

Hi, I'm trying to advertise my app as iBeacon, everything works well with Android (it works in foreground and background as well), but in iOS it doesn't work in background.

Here is my code:

   cordova.plugins.locationManager.requestAlwaysAuthorization();

    var uuid = '588490E5-2884-4046-9F2B-78FFE47C796A';
    var identifier = 'TEST';
    var minor = 1000;
    var major = 1;
    var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid, major, minor);

    var delegate = new cordova.plugins.locationManager.Delegate();

    delegate.peripheralManagerDidStartAdvertising = function(pluginResult) {
        console.log('peripheralManagerDidStartAdvertising: '+ JSON.stringify(pluginResult.region));
    };

    delegate.peripheralManagerDidUpdateState = function(pluginResult) {
        console.log('peripheralManagerDidUpdateState: '+ pluginResult.state);
    };

    cordova.plugins.locationManager.setDelegate(delegate);

    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();

I added NSLocationAlwaysAndWhenInUseUsageDescription via config-file, it adds in to Info.plist (i checked in Xcode).

I enabled Location updates in Capabilities.

Testing on iPhone 6s, iOS 11.0.1 Cordova 7.1.0 iOS platform 4.5.4

stevenatciklum commented 5 years ago

@jarekskuder Running into similar issues... were you able to resolve anything?

jeremyTyriaux commented 5 years ago

same here...