GithubHelp home page GithubHelp logo

Comments (28)

sign2k avatar sign2k commented on September 3, 2024 3

We had the same problem.

Adding
self.locationManager.allowsBackgroundLocationUpdates = YES;
to the init method of RNIBeacon.m solved the problem.

https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates

maybe some function like

RCT_EXPORT_METHOD(allowsBackgroundLocationUpdates:(BOOL)allow)
{
  self.locationManager.allowsBackgroundLocationUpdates = allow;
}

would be helpful. This would allow the developer to control, when ranging in background really needed.

from react-native-beacons-manager.

innyso avatar innyso commented on September 3, 2024 1

Hi All,

I enabled background update by setting BeaconsManager.allowsBackgroundLocationUpdates(true) in the beginning of componentWillMount

I would like to know if this suppose to work for only single region or multi region as I noticed when I am sending ranging information from multi region I will only get one region update instead of all of it.
Or if I am doing something wrong so not all then not all region ranging update are send while in phone is locked.

Thank you :D

from react-native-beacons-manager.

d0uub avatar d0uub commented on September 3, 2024 1

I just solve it by change the privacy.
as your suggested, both "location always use" + "location when in use" description must fill something to make it works in the plist!

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

I did try to add:
Beacons.setBackgroundBetweenScanPeriod(1)
which using it I sometimes get push on background (I get inconsistent behaviour – sometimes I do get, sometimes I don’t), but still - not at all when the app is killed.

Also, I now get the following warning:

TypeError:_reactNativeBeaconsManager2.default.setBckgroundBetweenScanPeriod is not a function`

from react-native-beacons-manager.

MacKentoch avatar MacKentoch commented on September 3, 2024

Thank you @oferRounds for this detailed issue.

Master branch contains a merged PR to try to fix these inconsistencies in iOS (drop of DeviceEventEmitter in favor of Beacons.BeaconsEventEmitter: see CHANGELOG).

Would you give a try (hoping it solves it)?

Get master branch version:

npm install git+https://github.com/MacKentoch/react-native-beacons-manager.git

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

@MacKentoch - thanks! Do you mean it suppose to suppose to solve the background/app killed issue?

@eurobob - oh, you’re right! Sorry for this :(

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

@oferRounds I was having issues with detection when the app is killed but have been having much more consistent behaviour with a small addition to the library. Try the code from my pull request and see how it works:

#58

Be aware that you should be able to detect when monitoring and ranging is working, but if you are in range of the beacon when starting the app you will not trigger the entry event from monitoring. I'm trying to find a workaround for this now.

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

Replied directly on issue #58.

So it now does works great for me in the background/foreground, but not when the app is killed. The problems are the app either only wakes up once, when it enters the region (i.e., I would like to have the control to detect the proximity and only do something on an immediate event) or it doesn’t wake up at all.

@eurobob I saw some posts that mention that when the app wakes up, in the didFinishLaunchingWithOptions we should reactivate the location manager. Is that true from what you aware of? If so, how can get the location manager’s instance?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

@MacKentoch - I did the update, but I get the error: Property 'BeaconsEventEmitter' does not exist on type 'typeof 'react-native-beacons-manager'.

Any idea?

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

Can you share more code from the file you're working in?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

Thanks! Sure:

import { DeviceEventEmitter, EmitterSubscription, Alert, Platform, AppState } from 'react-native'
import Beacons from 'react-native-beacons-manager'
import { toggleClock } from '../actions'
const PushNotification = require('react-native-push-notification')

const region = {
  identifier: ***,
  uuid: ***,
  major: ***,
  minor: ***
}

let didEnterRegionListener: EmitterSubscription = null

export default class TimeLogService {

  static trackUserLocation(dispatch: any) {

    if (didEnterRegionListener === null) {
      didEnterRegionListener = Beacons.BeaconsEventEmitter.addListener(
        'regionDidEnter',
        () => {

          if (AppState.currentState === 'active') {
            Alert.alert(
              'Toggle clock sent.',
              '',
              [
                {text: 'OK', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}
              ],
              { cancelable: false }
            )
          } else {
            PushNotification.localNotification({
              message: 'Toggle clock sent.'
            })
          }

          dispatch(toggleClock())
        }
      )

      if (Platform.OS === 'ios') {
        Beacons.requestAlwaysAuthorization()

        Beacons.startMonitoringForRegion(region)
        Beacons.startRangingBeaconsInRegion(region)

        Beacons.startUpdatingLocation()
      } else {
        Beacons.detectIBeacons()
        try {
          Beacons.startRangingBeaconsInRegion(region)
          console.log(`Beacons ranging started succesfully!`)
        } catch (error) {
          console.log(`Beacons ranging not started, error: ${error}`)
        }
      }
    }
  }
}

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

It sounds like you might still be using v1.0.7? Or are you installing the package directly from the git repository?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

I followed your suggestion and installed it by:
npm install git+https://github.com/MacKentoch/react-native-beacons-manager.git

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

I'm not sure what could be the problem then. Just to be thorough, maybe unlink it and uninstall the npm package, then try again?

You can also use my fork to include this pull request:

npm install git+https://github.com/eurobob/react-native-beacons-manager.git

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

That’s an idea! I’ll do that.

from react-native-beacons-manager.

MacKentoch avatar MacKentoch commented on September 3, 2024

PR #58 is merged in master CHANGELOG

from react-native-beacons-manager.

eurobob avatar eurobob commented on September 3, 2024

@oferRounds going back to the initial problem, i've found that in debugging mode sometimes the app can take a long time to load (bad wifi or whatever), which eats into the time window allocated to take action on the region entry from the monitoring. Perhaps you could try a production build to see if it works that way?

from react-native-beacons-manager.

MacKentoch avatar MacKentoch commented on September 3, 2024

Thank you @sign2k for sharing.

This is definitely a good fix to add.

from react-native-beacons-manager.

MacKentoch avatar MacKentoch commented on September 3, 2024

As suggested by @sign2k, I added:

/**
 * set background location updates to ensure monitoring when app is killed or in background mode
 *
 * @param {boolean} [allow=false] allow or disallow background modes
 */
function allowsBackgroundLocationUpdates(allow: boolean = false): void {
  BeaconsManager.allowsBackgroundLocationUpdates(allow);
}

Please note this requires iOS9+ (it should not be a problem, since iPhone owners should be at iOS10 for more than 90%)

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

@MacKentoch, @sign2k

I’m facing the issue also in Android. I.e, on both platform, when the app is killed, the beacon is sometimes not detected and the app is not woken up. Otherwise — when in foreground or background - it works great.

Two questions please:

  1. Is using allowsBackgroundLocationUpdates should affect monitoring also? Anyhow, I’ll test it now and follow up with results.
  2. Any solution to Android?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

@eurobob any findings perhaps from your tests?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

On iOS - I just added the code to AppDelegate.m according to Estimote guide, and now it works! Even when the app was killed by the user.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
  if([launchOptions objectForKey:@"UIApplicationLaunchOptionsLocationKey"])
  {
    self.beaconManager = [ESTBeaconManager new];
    self.beaconManager.delegate = self;
    // don't forget the NSLocationAlwaysUsageDescription in your Info.plist
    [self.beaconManager requestAlwaysAuthorization];
    [self.beaconManager startMonitoringForRegion:[[ESTBeaconRegion alloc]
                                                  initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
                                                  identifier:@"AppRegion"]];
  }
  return YES;
}

-(void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region
{
  UILocalNotification *notification = [[UILocalNotification alloc] init];
  notification.alertBody = @"Enter region";
  notification.soundName = UILocalNotificationDefaultSoundName;

  [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
 
-(void)beaconManager:(ESTBeaconManager *)manager didExitRegion:(ESTBeaconRegion *)region
{
  UILocalNotification *notification = [[UILocalNotification alloc] init];
  notification.alertBody = @"Exit region";
  notification.soundName = UILocalNotificationDefaultSoundName;
 
  [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

Do we want to address this in the library?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

As for Android, I see in Estimote docs that the following scenario is indeed not handled

Keep in mind that if the app is killed by device memory requirements, it is possible to carry out background monitoring to relaunch it. 
However, if the user killes the app background monitoring won't work.

Any idea for a workaround?

from react-native-beacons-manager.

oferRounds avatar oferRounds commented on September 3, 2024

I see that Estimote added this feature in their new coming up SDK.

See here: https://forums.estimote.com/t/alpha-4-monitoring/7516

And here: Estimote/Android-Fleet-Management-SDK#62 (comment)

Can we add something like this here also? What do you think?

from react-native-beacons-manager.

d0uub avatar d0uub commented on September 3, 2024

@MacKentoch , i tried v1.1 and background scanning not work. (i am in debug mode) do you have any idea?

version:
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-beacons-manager": "git+https://github.com/MacKentoch/react-native-beacons-manager.git"

Source:

import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import Beacons from 'react-native-beacons-manager';

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component {
componentWillMount() {
Beacons.allowsBackgroundLocationUpdates(true)
Beacons.requestAlwaysAuthorization()
Beacons.shouldDropEmptyRanges(true);
const region = {
identifier: ***,
uuid: ***
};
Beacons.startMonitoringForRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.warn('Beacons monitoring started succesfully'))
.catch(error =>
console.warn(Beacons monitoring not started, error: ${error}),
);
Beacons.startRangingBeaconsInRegion(region) // or like < v1.0.7: .startRangingBeaconsInRegion(identifier, uuid)
.then(() => console.warn('Beacons ranging started succesfully'))
.catch(error =>
console.warn(Beacons ranging not started, error: ${error}),
);
Beacons.startUpdatingLocation()

}

componentDidMount() {

this.authStateDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
  'authorizationStatusDidChange',
  info => console.warn('authorizationStatusDidChange: ', info),
);

// Ranging: Listen for beacon changes
this.beaconsDidRangeEvent = Beacons.BeaconsEventEmitter.addListener(
  'beaconsDidRange',
  data => {
    console.warn(data)
  }
);

// monitoring events
this.regionDidEnterEvent = Beacons.BeaconsEventEmitter.addListener(
  'regionDidEnter',
  ({ uuid, identifier }) => {
   console.warn('monitoring - regionDidEnter data: ', { uuid, identifier });
 }

);

this.regionDidExitEvent = Beacons.BeaconsEventEmitter.addListener(
'regionDidExit',
({ identifier, uuid, minor, major }) => {
console.warn('monitoring - regionDidExit data: ', { identifier, uuid, minor, major });
}
);
}

render() {
return (


Welcome to React Native!


To get started, edit App.js


{instructions}


);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

from react-native-beacons-manager.

Gillinghammer avatar Gillinghammer commented on September 3, 2024

We had the same problem.

Adding
self.locationManager.allowsBackgroundLocationUpdates = YES;
to the init method of RNIBeacon.m solved the problem.

https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates

maybe some function like

RCT_EXPORT_METHOD(allowsBackgroundLocationUpdates:(BOOL)allow)
{
  self.locationManager.allowsBackgroundLocationUpdates = allow;
}

would be helpful. This would allow the developer to control, when ranging in background really needed.

I was not able to see ranging in the background until I found your post. Thank you fine sir, this is exactly what I needed!

from react-native-beacons-manager.

ger86 avatar ger86 commented on September 3, 2024

@oferRounds , can you show me what code did you use in your AppDelegate? Because I think you have pasted the one from Estimote but the needed for this library will be different. Thanks!

from react-native-beacons-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.