react-native-beacons-manager icon indicating copy to clipboard operation
react-native-beacons-manager copied to clipboard

On iOS it always asks for Bluetooth permission right on App launch, before any call to any method

Open nbastoWM opened this issue 4 years ago • 14 comments

Version

1.0.1 "react-native-beacons-manager": "git://github.com/MacKentoch/react-native-beacons-manager.git#53c1bda",

Platform

iOS

OS version

iOS 13.3.1

Steps to reproduce

  1. Install the package through git #53c1bda
  2. Launch the App in a device
  3. It asks the user for Bluetooth Permissions on App launch, without making any reference to the package methods in the Apps' code

Expected behavior

Only ask for bluetooth permission if the package was initialised or after calling any method from the package.

Actual behaviour

I'm not calling any method from the package but as the App is starting up it asks the user for bluetooth permission, even before it asks for the push notification permissions.

nbastoWM avatar Jun 12 '20 07:06 nbastoWM

We also have this problem, did you manage to solve it?

jdegger avatar Jul 30 '20 10:07 jdegger

Looks like when the main iOS module is initialised, it creates an ESSBeaconScanner: https://github.com/MacKentoch/react-native-beacons-manager/blob/2735284717985d1abdc9bab9ee67d4505025ad54/ios/RNiBeacon/RNiBeacon/RNiBeacon.m#L44

ESSBeaconScanner immediately initialises a CBCentralManager: https://github.com/MacKentoch/react-native-beacons-manager/blob/2735284717985d1abdc9bab9ee67d4505025ad54/ios/RNiBeacon/RNiBeacon/ESSBeaconScanner.m#L64

Couldn't confirm this via Apple's docs, but reading around StackOverflow (1, 2), it seems that as soon as a CBCentralManager is initialised it will request bluetooth permissions if they're not already granted.

So I wonder if this could be resolved by modifying ESSBeaconScanner, moving initialisation of CBCentralManager out of init and into startScanning (conditional on _centralManager not already having been initialised)?

Or perhaps it arguably belongs in requestAlwaysAuthorization or requestWhenInUseAuthorization? Probably makes more sense from a developer perspective.

chriswait avatar Aug 17 '20 11:08 chriswait

We also have this problem, did you manage to solve it?

HAven't sorted it yet. When I publish to the store, if in that app I don't use beacons I install the "normal" version of this package that doesn't ask for bluetooth permission if it's not used.

nbastoWM avatar Sep 30 '20 08:09 nbastoWM

In which react-native version you guys are trying this , for 0.63.3 I am getting error as "no listener registered" . any idea on how to solve this @nbastoWM @chriswait

kirantripathi avatar Nov 08 '20 05:11 kirantripathi

This is a huge blocker for adopting the 1.1.0 version for us, especially given that 1.1.0 is still not properly released and no release notes are available.

Might have to roll back to 1.0.7 and manually link

noway avatar Mar 01 '21 22:03 noway

@nbastoWM Hello, Any updates about this issue? Сould you solve it?

usichenko-nikita avatar Jul 14 '21 09:07 usichenko-nikita

For anyone needing a fix for this issue, I made the fix suggested by @chriswait. The fork is from https://github.com/benlui/react-native-beacons-manager (which is a fork from this repo). Check https://github.com/martinmanzo/react-native-beacons-manager

martinmanzo avatar Sep 06 '21 13:09 martinmanzo

Any fixes for this issue?

gaveen5555 avatar Oct 16 '21 05:10 gaveen5555

Hi @gaveen5555 , check my answer above.

martinmanzo avatar Oct 17 '21 15:10 martinmanzo

@martinmanzo I get an error like this when i tried your fix. What could be the reason for this? error: Error: Unable to resolve module ../../../../../BeaconMonitorTask from /Users/ninjauser/Desktop/project/my-project/node_modules/react-native-beacons-manager/lib/next/new.module.android.js:

gaveen5555 avatar Oct 18 '21 02:10 gaveen5555

@gaveen5555 you should create an empty BeaconMonitorTask.js file in the root of your project (at the same level of node_modules).

martinmanzo avatar Oct 18 '21 12:10 martinmanzo

@martinmanzo i tried creating a empty js file but then in xcode it gives out this error terminating with uncaught exception of type NSException

gaveen5555 avatar Oct 22 '21 09:10 gaveen5555

@gaveen5555 try to clean the build folder and build again and the review the docs of the new package to make sure everyting if fine. Sorry but whitout more info I can't do more.

martinmanzo avatar Oct 22 '21 13:10 martinmanzo

@gaveen5555 My solution was fork this react-native-beacons-manager and add next changes https://github.com/usichenko-nikita/react-native-beacons-manager/commit/665cc50a3665a9fff11c21a528d87cb4600b0749 I found out this solution by monitoring all forks of this lib (unfortunately I don't remember which one exactly..)
Pay attention that I did fork from git://github.com/MacKentoch/react-native-beacons-manager.git#53c1bda

usichenko-nikita avatar Oct 24 '21 10:10 usichenko-nikita