Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't activate advertising #310

Closed
andersborgabiro opened this issue Aug 12, 2017 · 11 comments
Closed

Can't activate advertising #310

andersborgabiro opened this issue Aug 12, 2017 · 11 comments
Assignees
Labels

Comments

@andersborgabiro
Copy link

andersborgabiro commented Aug 12, 2017

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:

  • Input values are valid.
  • status() isn't called.
  • No Javascript errors occur.
  • The delegate events never trigger.

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
Copy link

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
Copy link
Author

andersborgabiro commented Aug 15, 2017

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:
#305

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

@petermetz petermetz self-assigned this Sep 2, 2017
@petermetz
Copy link
Owner

@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
Copy link
Author

andersborgabiro commented Sep 2, 2017

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
Copy link
Author

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
Copy link
Owner

@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
Copy link
Author

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
Copy link
Contributor

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

@andersborgabiro
Copy link
Author

andersborgabiro commented Sep 14, 2017

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
Copy link
Author

andersborgabiro commented Sep 21, 2017

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
Copy link
Owner

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

@petermetz petermetz added question and removed bug labels Dec 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants