zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.04k stars 828 forks source link

Bluetooth request does not ask user and send denied response on iOS 12.4.2 #507

Open KristenGarnier opened 4 years ago

KristenGarnier commented 4 years ago

Bug report

Summary

Does not prompt the user for request when demanding the bluetooth permission on iphone 6. iOs version 12.4.2

When requesting the permissions with everything setup in .plist and pods it keeps returning 'denied' even tho the user has never seen bluetooth prompt.

The same configuration works fine with newer iOS version.

Also tested on fresh app, does not work with iOS 12 on version 2, but does on version 1

We also chained multiple promises to ask for permissions, but always get "denied"

Environment info

react-native-permissions version : 2.2.0

react-native info output:

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 253.81 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v12.6.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.2 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Library version: x.x.x

Steps to reproduce

  1. Install the library
  2. Run on an iOS 12 device (here iphone6, we do not know if it plays a role there)
  3. Check the output of the following promise
    PermissionRequest(
    PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL,
    )

Describe what you expected to happen:

  1. Expect to show user prompt or return granted

Reproducible sample code

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
  PERMISSIONS,
  request as PermissionRequest,
} from 'react-native-permissions';

PermissionRequest(
  PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL,
)
  .then(console.log)

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
zoontek commented 4 years ago

Hi. Did you check the "Bluetooth peripheral" capability in Xcode too?

KristenGarnier commented 4 years ago

Hi,

Yes, these ones are checked :

zoontek commented 4 years ago

@KristenGarnier Could you try 2.1.4 to check if the version 2.1.5 did not introduce a regression?

KristenGarnier commented 4 years ago

@zoontek We were using version 2.1.0 before, and it was not working either

But i will try on version 2.1.4 next time, see if it works there

bwindsor commented 4 years ago

I'm having exactly the same issue with version 2.1.2 and iOS version 12.4.8. The bluetooth peripheral capability is ticked in Xcode.

bwindsor commented 4 years ago

I've done some more research, it looks like this is not a bug in react-native-permissions. The problem is explained here: https://github.com/react-native-community/react-native-permissions/issues/458#issuecomment-623077980

@KristenGarnier you said you had Uses Bluetooth LE accessories checked, but didn't mention Acts as a Bluetooth LE accessory. This is probably the source of the problem.

You can see the source code for that react-native-permissions is doing under the covers here: https://github.com/react-native-community/react-native-permissions/blob/e9193c93c3c1f5e7d285bea3570f974481ee5956/ios/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m#L32-L55

For iOS 13, it uses CBManager which correctly requests permission to use Bluetooth. For iOS<=12, this general Bluetooth permission did not exist, however permission for the iPhone to act as a Bluetooth peripheral did exist. However, it is likely that your application is trying to act as a central, not a peripheral (hence why you would tick Uses Bluetooth LE accessories but leave Acts as a Bluetooth LE accessory unticked. So react-native-permissions requests permission to act as a bluetooth peripheral for iOS<=12, which will automatically be denied if Acts as a Bluetooth LE accessory is unchecked.

I would recommend the solution given in https://github.com/react-native-community/react-native-permissions/issues/458#issuecomment-622564566. If you only want to act as a central on iOS<=12, there is no need to request any bluetooth permissions at all.

Edit: If react-native-permissions wanted to reduce this confusion, perhaps there could be a PERMISSIONS.IOS.BLUETOOTH_CENTRAL which does the same as BLUETOOTH_PERIPHERAL on iOS 13, but always returns GRANTED on iOS<=12

KristenGarnier commented 4 years ago

Hi @bwindsor, thanks for your explaination ! I came here to say just what you said, that you do not need to request permission in iOS 12 or lower :)

That was quite confusing on our part and felt a bit like a "hack", I guess we are used to asking for permissions everywhere (which is a good thing IMO)

Still, there is maybe a need for this to be documented somewhere, so people don't end up confused as we were discovering this weird behaviour.

If someone can point me to where it would make sens to belong, i would be happy to document this findings 😄

Again thanks for your time ! Have a nice day

zoontek commented 4 years ago

If react-native-permissions wanted to reduce this confusion, perhaps there could be a PERMISSIONS.IOS.BLUETOOTH_CENTRAL which does the same as BLUETOOTH_PERIPHERAL on iOS 13, but always returns GRANTED on iOS<=12

That's probably the best solution. I'll try to write a permission handler for it soon.

SnaiNeR commented 3 years ago

@bwindsor thank you for your exporering ! same problem was

mattahorton commented 3 years ago

any update on the bluetooth-central handler?

mikehardy commented 3 years ago

https://github.com/zoontek/react-native-permissions/pulls?q=is%3Apr+is%3Aopen+bluetooth

Looks like zero PRs in the queue

mikehardy commented 7 months ago

Gosh no @zxar7 I performed a trivial search here and saw no activity. Did you do that? Or propose a PR? I don't see a PR from you. I guess no updates.

People in the future: "do the work and propose a PR" is the short answer to "are there any updates?"