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

WIP: 2.0.0 #291

Merged
merged 60 commits into from
Sep 28, 2019
Merged

WIP: 2.0.0 #291

merged 60 commits into from
Sep 28, 2019

Conversation

zoontek
Copy link
Owner

@zoontek zoontek commented Feb 3, 2019

Hello everyone ! 🙂

As you might know, Apple will now reject your app if your code contains unused permissions request code / usage descriptions (#240)

I started working on a 2.0.0 to tackle this problem, using CocoaPods subspecs.
A full example is available here: https://github.com/yonahforst/react-native-permissions/tree/2.0.0/example

platform :ios, '9.0'

target 'RNPermissionsExample' do
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'DevSupport',
  ]

  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party deps podspec link
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'RNPermissions', :path => '../node_modules/react-native-permissions/ios', :subspecs => [
    'Core',
    # Uncomment wanted permissions
    # 'BluetoothPeripheral',
    # 'Calendars',
    # 'Camera',
    # 'Contacts',
    # 'FaceID',
    # 'LocationAlways',
    # 'LocationWhenInUse',
    # 'MediaLibrary',
    # 'Microphone',
    # 'Motion',
    # 'Notifications',
    # 'PhotoLibrary',
    # 'Reminders',
    # 'Siri',
    # 'SpeechRecognition',
    # 'StoreKit',
  ]
end

It also have Android native code: we now supports unavailable result and openSettings() is back!

Current API:

import * as RNPermissions from "react-native-permissions";

RNPermissions.ANDROID_PERMISSIONS;
RNPermissions.IOS_PERMISSIONS;
RNPermissions.RESULTS;

RNPermissions.openSettings();
RNPermissions.check(permission);
RNPermissions.checkMultiple(permissions);
RNPermissions.request(permission);
RNPermissions.requestMultiple(permissions);

How does it works?

  • Until a permission is not requested, the result has good chances of being equals to RESULTS.DENIED (you can access the wanted ressources since it's not required yet)
  • If the feature is not available yet, (the user has an old version of iOS / android, does not have faceID on his device, etc.) then the results will be equals to RESULTS.UNAVAILABLE
  • On Android, if the user deny the request without checking the Never ask again box, results will still be equals to RESULTS.DENIED, if he checks it, the result will be equals to RESULTS.NEVER_ASK_AGAIN.
  • On iOS, if the user deny the request, the result will be equals RESULTS.NEVER_ASK_AGAIN (since it can't be ask again in the app, the user will have to open settings to change the permission value)
  • If the request is allowed, result will be equals to RESULTS.GRANTED

OK, now what ?

I need you help to :

Thanks in advance everyone, let's ship this thing ! 😃

Edit: I would be nice to transfer this repo to the react-native-community since @yonahforst does not seems to be active here anymore. A bunch of new collaborators could be a good thing.

@bencergazda
Copy link

@zoontek I am really happy to find this pull request, waiting for the new version.

Just a side note after I installed the new version yesterday: after some hours of trying to make it work on iOS, I realized that RCTBlob, DoubleConversion, glog and folly needs to be added to the Podfile (otherwise the app crashes when calling RNPermissions.check() or RNPermissions.request()). I did notice this only after checking the example app and I think this should be noticed here.

My Podfile looks somehow like this:

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'RNPermissionsExample' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for RNPermissionsExample
  pod 'React', path: '../node_modules/react-native', :subspecs => [
      'Core',
      'RCTActionSheet',
      'RCTAnimation',
      'RCTBlob',
      'RCTGeolocation',
      'RCTImage',
      'RCTLinkingIOS',
      'RCTNetwork',
      'RCTSettings',
      'RCTText',
      'RCTVibration',
      'RCTWebSocket',
      'DevSupport'
  ]

  # Explicitly include Yoga if you are using RN >= 0.42.0
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  # Third party deps podspec link
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'RNPermissions', :path => '../node_modules/react-native-permissions/ios', :subspecs => [
    'Core',
    # Uncomment wanted permissions
    # 'BluetoothPeripheral',
    # 'Calendars',
    'Camera',
    # 'Contacts',
    'FaceID',
    # 'LocationAlways',
    'LocationWhenInUse',
    # 'MediaLibrary',
    # 'Microphone',
    # 'Motion',
    # 'Notifications',
    # 'PhotoLibrary',
    # 'Reminders',
    # 'Siri',
    # 'SpeechRecognition',
    # 'StoreKit',
  ]

end

@zoontek
Copy link
Owner Author

zoontek commented Feb 6, 2019

@bencergazda Thanks, I edited the PR! The CocoaPods install for React is currently discuted here: react-native-community/discussions-and-proposals#96, I hope better officiel documentation will come about it.

@bencergazda
Copy link

@zoontek One more feedback: just wanted to submit a new iOS build to TestFlight, but it was rejected with a Missing Purpose String in Info.plist File warning. App Store asks for a NSMicrophoneUsageDescription, but I didn't want to use Microphone. Only Camera, FaceID and LocationWhenInUse should be added to the code.

I am using react-native-camera, and explicitly set captureAudio to false. As the documentation says that NSMicrophoneUsageDescription is only optional, do you think that the issue should be resolved here?

Here's my Podfile configration:

...
pod 'RNPermissions', :path => '../node_modules/react-native-permissions/ios', :subspecs => [
  'Core',
  # Uncomment wanted permissions
  # 'BluetoothPeripheral',
  # 'Calendars',
  'Camera',
  # 'Contacts',
  'FaceID',
  # 'LocationAlways',
  'LocationWhenInUse',
  # 'MediaLibrary',
  # 'Microphone',
  # 'Motion',
  # 'Notifications',
  # 'PhotoLibrary',
  # 'Reminders',
  # 'Siri',
  # 'SpeechRecognition',
  # 'StoreKit',
]
...

@zoontek
Copy link
Owner Author

zoontek commented Feb 6, 2019

@bencergazda If you don't install the subspec 'Microphone', microphone access code request is not included in your code. Looks like more an issue with react-native-camera: react-native-camera/react-native-camera#2085 (comment)

That's precisely why this new version of react-native-permissions is divided in a bunch of submodules.

@bencergazda
Copy link

@zoontek Indeed, thanks for investigating this!

@nghiatv
Copy link

nghiatv commented Feb 20, 2019

how to install version 2.0.0 on npm?

@zoontek
Copy link
Owner Author

zoontek commented Feb 20, 2019

@nghiatv It's not on npm yet. Maybe should I write basic documentation and publish it as 2.0.0-alpha.1?

@bencergazda
Copy link

bencergazda commented Feb 21, 2019

@zoontek I think it really deserves an alpha state.

One more thing: after clean yarn install + pod install the build fails in XCode 10.1 with the following error:

/node_modules/react-native-permissions/ios/RNPermissionsManager.m:224:47: Values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead

The two affected lines:
https://github.com/yonahforst/react-native-permissions/blob/2.0.0/ios/RNPermissionsManager.m#L224
https://github.com/yonahforst/react-native-permissions/blob/2.0.0/ios/RNPermissionsManager.m#L252

Replacing

reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);

in both lines to

reject([NSString stringWithFormat:@"%ld", (long)error.code], error.localizedDescription, error);

fixes the error.

@VincentCATILLON
Copy link

If you have something almost stable, an alpha could be great to be able to allow permissions on RN 0.52+

@kaueDM
Copy link

kaueDM commented Sep 19, 2019

Amazing work. I'm looking to use it in a new project, any idea when this beauty will be released @zoontek ?

@zoontek
Copy link
Owner Author

zoontek commented Sep 19, 2019

@kaueDM You can already install the RC1, but expect the final version next week 😏

@zoontek
Copy link
Owner Author

zoontek commented Sep 21, 2019

If you struggle understanding the permission flow, I made some flowcharts: https://github.com/react-native-community/react-native-permissions/blob/2.0.0/README.md#understanding-lifecycle

@mikehardy
Copy link

If you struggle understanding the permission flow, I made some flowcharts: /README.md@2.0.0#understanding-lifecycle

That is ace @zoontek !

@petekp
Copy link

petekp commented Sep 25, 2019

@zoontek Curious if it's possible / feasible to detect the status of these settings for Face ID / Touch ID on iOS:

These are likely just OS-specific settings and unavailable to sandboxed apps, but am curious whether these are available as currently it doesn't appear possible to detect whether a user has disabled Face ID / Touch ID on their iOS device, only whether it is UNAVAILABLE (ie. non-existent) or it's been BLOCKED for your specific app.

How would one detect whether Face ID / Touch ID is "DISABLED" or just not preferred? This may just require providing an in-app configuration setting.

@zoontek zoontek merged commit 4b800f9 into master Sep 28, 2019
@zoontek zoontek deleted the 2.0.0 branch September 28, 2019 11:38
@zoontek
Copy link
Owner Author

zoontek commented Sep 28, 2019

@petekp I will check but it will not be my top priority (testing, DX, ecosystem adoption will be)!

For everyone here following this PR progression for a few months, I'm honored to say that it has been shipped! 🎉
You can check the (probably incomplete since it has been rewritten from zero) changelog here: https://github.com/react-native-community/react-native-permissions/releases/tag/2.0.0

I also close a bunch of issues / PR which are not relevant since it is out (sorry for that, but I had to cleanup… If the issue is still here, don't hesitate to open a new one on the same subject!)

Sponsor button

P.-S.: I added a Sponsor button on the repository (only PayPal for now, I will switch to GitHub Sponsor when I'll have access to it). If you use this on a professional project and think it's good work and save you a huge amount of time / money, consider supporting it! 🙂

P.-S. 2: I am still looking for new members / collaborators on the project! 😅

@SeanDunford
Copy link

SeanDunford commented Feb 5, 2021

If you struggle understanding the permission flow, I made some flowcharts: https://github.com/react-native-community/react-native-permissions/blob/2.0.0/README.md#understanding-lifecycle

Hey @zoontek did you use something to gen these flow charts they are dreamy 🤩

Sorry to bump an old thread but i didn't want to create a new issue just for a qq.

@zoontek
Copy link
Owner Author

zoontek commented Feb 5, 2021

@SeanDunford I used https://monodraw.helftone.com/ 🙂

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

Successfully merging this pull request may close these issues.