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

Can't activate advertising #310

Closed andersborgabiro closed 6 years ago

andersborgabiro commented 7 years ago

I made a simple beacon advertiser app for iOS some time ago, and the published version still works, but when building with the latest cordova-plugin-ibeacon for cli-6.5.0 or cli-7.0.1 there's now no advertising taking place. To be on the safe side I now follow the example given in the documentation precisely.

Thanks in advance for any pointers, Anders

Verified:

A code snippet of the essentials:

cordova.plugins.locationManager.requestWhenInUseAuthorization();

...

    var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(BeaconIdentifier, uuid, majorid, minorid);

    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) {
            //status("Advertising", uuid + ", " + majorid + ", " + minorid);
            cordova.plugins.locationManager.startAdvertising(beaconRegion).fail(console.error).done();
            setAdvertiseButton(true);
            setIDs();
        }
        else {
            status("Error", "Beacon advertising is not supported");
        }
    }).fail(function(e) {
        status("Error", "Beacon advertising failed: " + e);
    }).done();
brandon-objectstudio commented 7 years ago

I am having the same problem. iOS 10.3. I commented on the issue #283 you referenced above.

Is this plugin being actively maintained?

andersborgabiro commented 7 years ago

It doesn't seem to be maintained anymore. Peter Metz would know.

I added cordova-plugin-ios-ble-permissions, that I use in another project, but that didn't change the behavior, and AFAIK it was only needed to get the other project approved by Apple.

There's at least one critical pull request, so it would be a bummer if it's not worked on anymore: https://github.com/petermetz/cordova-plugin-ibeacon/pull/305

As I use PhoneGap Build, I can't make use of pull requests, unless they are also published.

petermetz commented 7 years ago

@andersborgabiro @brandon-applied Can you confirm that the capabilities are set correctly in Xcode?

I just added a new screen to the quickstart app (v2.1.0) and it works fine, but only if I have this set:

screen shot 2017-09-01 at 7 54 56 pm
andersborgabiro commented 7 years ago

I tried cordova-custom-config with these settings:

    <config-file platform="ios" target="*-Info.plist" parent="UIBackgroundModes">
        <array>
            <string>location</string>
        </array>
    </config-file>

    <config-file platform="ios" target="*-Info.plist" parent="NSLocationAlwaysUsageDescription">
        <string>This app requires constant access to your location in order to track your position, even when the screen is off.</string>
    </config-file>

    <config-file platform="ios" target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
        <string>This app will now only track your location when the screen is on and the app is displayed.</string>
    </config-file>

NSLocation... show up in the IPA Info.plist, but not UIBackgroundModes. The syntax is according to examples at https://www.npmjs.com/package/cordova-custom-config.

I also tried invoking cordova-plugin-ble-central, assuming it would set it, but that didn't fix it.

I'll do some more experimenting and report back if I get this to work.

andersborgabiro commented 7 years ago

I also added this (as recommended by another issue report), to no avail.

                var delegate = new cordova.plugins.locationManager.Delegate();
                cordova.plugins.locationManager.setDelegate(delegate);
petermetz commented 7 years ago

@andersborgabiro If the UIBackgroundModes setting is missing, it probably won't ever work. So in my opinion you should focus on the root cause of that. If I remember correctly you are using Phonegap Build, maybe the right direction is to check with their issue tracker if this has a known solution specific to PGB?

andersborgabiro commented 7 years ago

cordova-plugin-config won't work with PhoneGap Build:

This plugin WILL NOT WORK with remote ("Cloud") build environments that do not support the execution of this plugin's hook scripts. This includes: Phonegap Build Intel XDK Telerik Appbuilder Ionic Cloud

I haven't found any plugin that specifically sets UIBackgroundModes to location. cordova-plugin-background-mode sets it to audio though.

This is not very critical, so I'll leave it be for now.

mgrubinger commented 7 years ago

confirming, for further reference: as @petermetz stated, Background Mode -> Location updates must be enabled to use ibeacon advertising.

andersborgabiro commented 7 years ago

I could add the setting. I missed that they changed to edit-config in cli-7.0.1, so this does it (for <platform name="ios"> in config.xml). Still, the app has to be visible for advertising to work.

    <edit-config file="*-Info.plist" target="UIBackgroundModes" mode="merge">
        <array>
            <string>location</string>
        </array>
    </edit-config>

This means there's no need for cordova-plugin-custom-config in this case (that didn't help anyway), even for PhoneGap Build, Ionic and similar.

andersborgabiro commented 7 years ago

Advertising also works in iOS 11 with the above setting. The question asked is different, but I chose "Always". Having the app visible still applies.

petermetz commented 6 years ago

Added an entry about this to the FAQ: https://github.com/petermetz/cordova-plugin-ibeacon/blob/v3.x/FAQ.md

Thanks for the investigation @andersborgabiro