react-native-beacons-manager
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
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
- Install the package through git #53c1bda
- Launch the App in a device
- 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.
We also have this problem, did you manage to solve it?
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.
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.
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
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
@nbastoWM Hello, Any updates about this issue? Сould you solve it?
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
Any fixes for this issue?
Hi @gaveen5555 , check my answer above.
@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 you should create an empty BeaconMonitorTask.js file in the root of your project (at the same level of node_modules).
@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 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.
@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