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

Add support for notifyOnEntry, notifyOnExit parameters #2

Open
petermetz opened this issue Apr 2, 2014 · 13 comments
Open

Add support for notifyOnEntry, notifyOnExit parameters #2

petermetz opened this issue Apr 2, 2014 · 13 comments
Assignees
Milestone

Comments

@petermetz
Copy link
Owner

CLRegion.h defines these parameters below.
Goal: Expose these properties for the Javascript runtime via the plugin.

/*
 *  notifyOnEntry
 *
 *  Discussion:
 *    App will be launched and the delegate will be notified via locationManager:didEnterRegion:
 *    when the user enters the region. By default, this is YES.
 */
@property (nonatomic, assign) BOOL notifyOnEntry __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);

/*
 *  notifyOnExit
 *
 *  Discussion:
 *    App will be launched and the delegate will be notified via locationManager:didExitRegion:
 *    when the user exits the region. By default, this is YES.
 */
@property (nonatomic, assign) BOOL notifyOnExit __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_7_0);


@petermetz petermetz self-assigned this Apr 2, 2014
@simkli
Copy link

simkli commented Apr 7, 2014

Is it possible to create a local notification then? That would be really awesome (:

@petermetz
Copy link
Owner Author

It is possible but for the notification you will need to utilize another Cordova plugin.

@petermetz petermetz added this to the 2.0.0 milestone Apr 10, 2014
@petermetz petermetz modified the milestones: 2.0.0, 2.1 Jul 6, 2014
@morrissinger
Copy link

Would completing this ticket be needed in order to use this plugin to configure my application to wake from a closed or background state in response to entering an iBeacon region?

@petermetz
Copy link
Owner Author

Hi @morrissinger,

No, that should work out of the box with the current codebase. I'm writing should, because I only ever tested it with circular regions but that's definitely working and so should with beacons too.

Peter

@morrissinger
Copy link

@petermetz , first of all, thank you for being so responsive.

I'm a little confused about how to do this from the examples in your readme. I am looking under the "Start Monitoring for a Single iBeacon" section. If I call startMonitoringForRegion() in your example, is that going to automatically start region monitoring even when the app is closed?

@petermetz
Copy link
Owner Author

@morrissinger, yepp that's how it should work. From the calling side it should be transparent whether the app was running or not. Theoretically... :-)

@morrissinger
Copy link

@petermetz -- awesome. Thanks for your help. I'll post an update with my results.

@morrissinger
Copy link

I tried this out by using the PhoneGap local notification plugin (https://github.com/katzer/cordova-plugin-local-notifications) to generate location notifications when I entered and exited regions, and I can confirm that even with the app completely closed (i.e., double-tap home button and swipe app up), and the phone not active (i.e., screen is black), this plugin is able to do region monitoring. Excellent.

N.B.: I have not tested on Android.

@Ranjan-2014
Copy link

@morrissinger, Can you please share some snippet on how you are implementing in the call of startMonitoringForRegion()? It seems to be not working with the same.

didEnterRegion: function(pluginResult) {
window.plugin.notification.local.add({ message: 'Exit!' });
}
Is this necessary to run the app in the background to make it work(notify on entering a region)? Or I am doing something wrong here.
Also, I do see, didStartMonitoringForRegion is giving same pluginresult when beacon is off and on.
Appreciate your response....Thanks

@morrissinger
Copy link

@petermetz -- question: given that these two properties (notifyOnEntry and notifyOnExit) are not exposed to the JavaScript side of the plugin presently, what values are being supplied to these properties by default?

The reason I ask is thatI have set up an app with your plugin and all it does is set a local notifications whenever the phone enters or exits a region. I have also installed the Locate app by Radius (https://itunes.apple.com/us/app/locate-beacon/id738709014?mt=8), which ostensibly does the same thing. I have both apps listening to my Estimote iBeacons, and yet, with both apps closed, Locate appears to pick up the iBeacons far more frequently and also picks seems to pick them up every time I turn on the screen to my iPhone.

With the Locate app operating as a sort of control in this experiment, one would think that the same iPhone would detect the same iBeacons at approximately the same times. Yet this is not the case. Thus, I am looking for anything that may be configured differently between the two and these two properties caught my eye.

@petermetz
Copy link
Owner Author

@morrissinger

By default, both notifyOnEntry and notifyOnExit are set to YES, according to the documentation of Apple (see the description of this issue for reference).

The difference between Locate Beacon and the Cordova iBeacon plugin is definitely not because of the two mentioned properties, since they are both enabled by default.

My guess is that Locate Beacon might be using the iOS Core Bluetooth API under the hood, to be a bit more sophisticated than the simplistic Core Location API (which is used by this plugin).

This is just pure speculation though, the only surefire way to tell if you go and ask Radius Networks about their code. :-)

Peter

@morrissinger
Copy link

Ransome14: Here is what I did to get it working. Note, I needed to use the localnotification plugin as well to ensure that I could actually receive an event with the app closed. An alert() is not sufficient. You need to use a method that iOS provides for actually delivering a message to a user when an app is closed. Local notifications are a perfect method for this.

        var createLocalNotification = function (message) {
            window.plugin.notification.local.add({
                title:   'iBeaconSpike1',
                message: message
            });
        };

        var delegate = new cordova.plugins.locationManager.Delegate().implement({

            didDetermineStateForRegion: function (pluginResult) {
                createLocalNotification('[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult));
            },

            didStartMonitoringForRegion: function (pluginResult) {
                createLocalNotification('didStartMonitoringForRegion:' + JSON.stringify(pluginResult));
            },

            didRangeBeaconsInRegion: function (pluginResult) {
                createLocalNotification('[DOM] didRangeBeaconsInRegion: ' + JSON.stringify(pluginResult));
            }

        });

        var uuid = 'MY UUID';
        var identifier = 'JUST AN IDENTIFIER PASSED IN ON THE MESSAGE';
        var minor = /* MY MAJOR */;
        var major = /* MY MINOR */;
        var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid, major, minor);

        cordova.plugins.locationManager.setDelegate(delegate);
        cordova.plugins.locationManager.startMonitoringForRegion(beaconRegion)
                .fail(console.error)
                .done();

@petermetz petermetz modified the milestones: 3.2, 2.1 Sep 24, 2014
@sebastianh84
Copy link

Hi I monitor a single beacon. The didDetermineStateForRegion with notification works fine.
Now i want to notify the user just one time if he enters the region - just to say "hello please open your app now" - and only if he is about 4meters away from the beacon. The user should be notified if the app is closed - is that possible? something like:

     delegate.didDetermineStateForRegion = function (pluginResult) {
            //window.alert('[DOM] didDetermineStateForRegion: ' + JSON.stringify(pluginResult));
           if ( notAlreadyNotified == true && distanceToBeacon < 4 meters && appIsInBackground)
            {
                createLocalNotification('Welcome to our company please open your app ' + JSON.stringify(pluginResult.state));notAlreadyNotified = false;

            }               
        };

@petermetz petermetz modified the milestones: 3.4, 3.2 May 25, 2015
@petermetz petermetz modified the milestones: 3.5, 3.4 Feb 14, 2016
@petermetz petermetz modified the milestones: v3.5, v3.4.1 Dec 27, 2017
ctayl referenced this issue in BuildFire/cordova-plugin-ibeacon Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants