Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KristenGarnier opened this issue Sep 1, 2020 · 12 comments

Comments

@KristenGarnier
Copy link

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
Copy link
Owner

zoontek commented Sep 2, 2020

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

@KristenGarnier
Copy link
Author

Hi,

Yes, these ones are checked :

  • Uses Bluetooth LE Accessories
  • Background fetch
  • Background processing

@zoontek
Copy link
Owner

zoontek commented Sep 8, 2020

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

@KristenGarnier
Copy link
Author

@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
Copy link

bwindsor commented Sep 8, 2020

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
Copy link

bwindsor commented Sep 9, 2020

I've done some more research, it looks like this is not a bug in react-native-permissions. The problem is explained here: #458 (comment)

  • Ticking Uses Bluetooth LE accessories adds the bluetooth-central background mode
  • Ticking Acts as a Bluetooth LE accessory adds the bluetooth-peripheral background mode

@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 #458 (comment). 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
Copy link
Author

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
Copy link
Owner

zoontek commented Sep 11, 2020

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
Copy link

SnaiNeR commented Jan 14, 2021

@bwindsor thank you for your exporering !
same problem was

@mattahorton
Copy link

any update on the bluetooth-central handler?

@mikehardy
Copy link

@mikehardy
Copy link

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?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants