Estimote / react-native-proximity

React Native wrapper for Estimote Proximity SDK
Apache License 2.0
61 stars 38 forks source link

Getting error in android. while onEnterAction event is triggered. #40

Closed cfmitrah closed 5 years ago

cfmitrah commented 5 years ago
 onZoneEntered = context => {
        if (!this.props.isInCheckOutFlow) this.getCurrentStore();
        console.log('zone1 onEnter', context);
    };

    onZoneExit = context => {
        console.log('zone1 onExit', context);
    };

    onZoneChanged = contexts => {
        console.log('zone1 onChange', contexts);
    };

    componentDidMount() {
        RNEP.locationPermission.request().then(
            permission => {
                if (permission !== RNEP.locationPermission.DENIED) {
                    const credentials = new RNEP.CloudCredentials(ESTIMOTE_APP_ID, ESTIMOTE_APP_TOKEN);
                    const config = {
                        notification: {
                            title: 'Exploration mode is on',
                            text: "We'll notify you when you're next to something interesting.",
                            channel: {
                                id: 'exploration-mode',
                                name: 'Exploration Mode'
                            }
                        }
                    };
                    const beaconList = [
                        {
                            tag: 'shop1'
                        },
                        {
                            tag: 'shop2'
                        }
                    ];
                    var zones = [];
                    for (var i = 0; i < beaconList.length; i++) {
                        var zone = new RNEP.ProximityZone(5, beaconList[i].tag);
                        zone.onEnterAction = this.onZoneEntered;
                        zone.onExitAction = this.onZoneExit;
                        zone.onChangeAction = this.onZoneChanged;
                        zones.push(zone);
                    }
                    RNEP.proximityObserver.initialize(credentials, config);
                    RNEP.proximityObserver.startObservingZones(zones);
                }
            },
            error => {
                console.error('Error when trying to obtain location permission', error);
            }
        );

this is code i use to detect beacons. once it detects the beacon I'm getting this error undefined is not an object(evaluating 'n.get(e.zoneId).onEnterAction')

cfmitrah commented 5 years ago

@heypiotr any solutions?

heypiotr commented 5 years ago

Are you sure you're on 0.5.0? This was an error that happened in earlier versions when you didn't stop the observer properly before starting it again. In 0.5.0, it should instead give you a warning:

https://github.com/Estimote/react-native-proximity#already-observing

cfmitrah commented 5 years ago

It works after updating the package. Thanks!