Skip to content

Releases: zoontek/react-native-permissions

3.9.0

01 Sep 17:07
3347278
Compare
Choose a tag to compare

Run setup_permissions directly in your Podfile

This release come with an alternative permission linkage system for iOS: calling a function, setup_permissions inside your Podfile.
It offers the same benefits as the react-native setup-ios-permissions command (and actually perform the exact same operation), but it lives in your Podfile, so there's no need to run it each time your delete your node_modules directory.
The only requirement is to run pod install when your update your Podfile, which make much more sense 😄
This method also solves issues with monorepos / dependencies hoisting.

To migrate, remove your reactNativePermissionsIOS config, and update your Podfile:

# with react-native >= 0.72
- # Resolve react_native_pods.rb with node to allow for hoisting
- require Pod::Executable.execute_command('node', ['-p',
-   'require.resolve(
-     "react-native/scripts/react_native_pods.rb",
-     {paths: [process.argv[1]]},
-   )', __dir__]).strip

+ def node_require(script)
+   # Resolve script with node to allow for hoisting
+   require Pod::Executable.execute_command('node', ['-p',
+     "require.resolve(
+       '#{script}',
+       {paths: [process.argv[1]]},
+     )", __dir__]).strip
+ end

+ node_require('react-native/scripts/react_native_pods.rb')
+ node_require('react-native-permissions/scripts/setup.rb')
# with react-native < 0.72
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
+ require_relative '../node_modules/react-native-permissions/scripts/setup'

Then in the same file, call setup_permissions with the wanted permissions:

# …

platform :ios, min_ios_version_supported
prepare_react_native_project!

# ⬇️ uncomment wanted permissions
setup_permissions([
  # 'AppTrackingTransparency',
  # 'BluetoothPeripheral',
  # 'Calendars',
  # 'Camera',
  # 'Contacts',
  # 'FaceID',
  # 'LocationAccuracy',
  # 'LocationAlways',
  # 'LocationWhenInUse',
  # 'MediaLibrary',
  # 'Microphone',
  # 'Motion',
  # 'Notifications',
  # 'PhotoLibrary',
  # 'PhotoLibraryAddOnly',
  # 'Reminders',
  # 'Siri',
  # 'SpeechRecognition',
  # 'StoreKit',
])

# …

And run pod install. Done! ✨

📌 The React Native CLI plugin still exists and will not be removed until next major version.


  • request now accepts () => Promise<boolean> as rationale argument.
    This way, you can display custom rationale alerts instead of the native ones (fixes #710)

3.8.4

11 Jul 20:55
011277d
Compare
Choose a tag to compare
  • Only supports iOS 12.4+ with new architecture to prevent compilation issues (#786 by @hsjoberg)

3.8.3

03 Jul 08:52
3e19398
Compare
Choose a tag to compare
  • Use gradle namespace conditionally in order to improve old react native version compatibility.
    ⚠️ Note that this library officially now follows the React Native releases support policy. If you have been impacted by this bug, that means you are using an unsupported react native version and should upgrade to the latest.

3.8.2

03 Jul 08:49
1cd3714
Compare
Choose a tag to compare
  • Update Support mention

3.8.1

24 Jun 12:26
eb1ea77
Compare
Choose a tag to compare
  • Bump WindowsTargetPlatform by @TatianaKapos for react-native 0.72 compatibility in #771
  • Update Android config for react-native 0.73 compatibility by @felipemillhouse in #782

3.8.0

15 Mar 00:11
Compare
Choose a tag to compare

3.7.3

28 Feb 20:54
Compare
Choose a tag to compare
  • Add support for reactNativePermissionsIOS.json config file (closes #753)

3.7.2

27 Feb 01:13
Compare
Choose a tag to compare
  • Include missing react-native.config.js file in the npm package (#752 by @johnf)
  • Replace cosmiconfig dependency by read-pkg (fixes this issue)

3.7.1

26 Feb 14:05
Compare
Choose a tag to compare
  • Only request the App Tracking Transparency iOS permission when the app is focused (as it's not allowed in background).
    This means that this code (which was a workaround):
useEffect(() => {
  const listener = AppState.addEventListener('change', (status) => {
    if (Platform.OS === 'ios' && status === 'active') {
      request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
        .then((result) => console.log(result))
        .catch((error) => console.log(error));
    }
  });

  return listener.remove;
}, []);

       Can safely be replaced by:

useEffect(() => {
  if (Platform.OS === 'ios') {
    request(PERMISSIONS.IOS.APP_TRACKING_TRANSPARENCY)
      .then((result) => console.log(result))
      .catch((error) => console.log(error));
  }
}, []);

3.7.0

26 Feb 12:04
db42382
Compare
Choose a tag to compare

The new react-native setup-ios-permissions command

This release come with a new permission handler linkage system for iOS: the react-native setup-ios-permissions command. No need to update your Podfile file anymore, everything is now handled by your package.json.

The benefits from this solution are many, but the main ones are that it should fixes Xcode cache issues and the well-known use_frameworks issue (no more workaround needed! 🎉)

📌 The "old way" will continue to work until the next major update, but it has been removed from the latest documentation since this is not the preferred way anymore.

To migrate, remove all the extra code from your Podfile (and the use_frameworks workaround if you used it):

- # Convert all permission pods into static libraries
- pre_install do |installer|
-   Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
-   installer.pod_targets.each do |pod|
-     if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
-       def pod.build_type;
-         # Uncomment the line corresponding to your CocoaPods version
-         # Pod::BuildType.static_library # >= 1.9
-         # Pod::Target::BuildType.static_library # < 1.9
-       end
-     end
-   end
- end

target 'MyAwesomeApp' do

    # …

-  permissions_path = '../node_modules/react-native-permissions/ios'

-  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
-  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
-  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
-  pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"

Add a reactNativePermissionsIOS config in your package.json:

{
  "reactNativePermissionsIOS": [
    "Camera",
    "LocationWhenInUse",
    "Notifications",
    "SpeechRecognition"
  ]
}

Then run react-native setup-ios-permissions and pod install. That's all! ✨


P.-S. As these commands must be run each tome each time you update this config, delete your node_modules directory or update this library, I highly recommand to use a postinstall script to simplify this:

{
  "reactNativePermissionsIOS": [
    "Camera",
    "LocationWhenInUse",
    "Notifications",
    "SpeechRecognition"
  ],
  "devDependencies": {
    "pod-install": "0.1.38"
  },
  "scripts": {
    "postinstall": "react-native setup-ios-permissions && pod-install"
  }
}

Also in this release:

  • Update project dependencies to React Native 0.71 in order to prepare new architecture support.
  • Update the example app UI (with react-native-paper v5):