Skip to content

Commit

Permalink
3.9.0 (#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek authored Sep 1, 2023
1 parent a836e11 commit 3347278
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 155 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.eslintrc.js
dist/
example/
scripts/
fetchWindowsCapabilites.js
mock.js
node_modules
Expand Down
112 changes: 72 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,72 @@ $ yarn add react-native-permissions

### iOS

By default no permission handler is linked. To add one, update your `package.json` by adding the permissions used in your app, then run `npx react-native setup-ios-permissions` followed by `pod install` (`reactNativePermissionsIOS.json` is also supported).

_📌  Note that these commands must be re-executed each time you update this config, delete the `node_modules` directory or update this library. An useful trick to cover a lot of these cases is running them on `postinstall` and just run `yarn` or `npm install` manually when needed._

```json
{
"reactNativePermissionsIOS": [
"AppTrackingTransparency",
"BluetoothPeripheral",
"Calendars",
"Camera",
"Contacts",
"FaceID",
"LocationAccuracy",
"LocationAlways",
"LocationWhenInUse",
"MediaLibrary",
"Microphone",
"Motion",
"Notifications",
"PhotoLibrary",
"PhotoLibraryAddOnly",
"Reminders",
"Siri",
"SpeechRecognition",
"StoreKit"
],
"devDependencies": {
"pod-install": "0.1.38"
},
"scripts": {
"postinstall": "react-native setup-ios-permissions && pod-install"
}
}
```

Then update your `Info.plist` with wanted permissions usage descriptions:
1. By default, no permissions are setuped. So first, require the `setup` script in your `Podfile`:

```diff
# 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')
```

```diff
# 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'
```

2. Then in the same file, add a `setup_permissions` call with the wanted permissions:

```ruby
#

platform :ios, min_ios_version_supported
prepare_react_native_project!

# ⬇️ uncomment wanted permissions (don't forget to remove the last comma)
setup_permissions([
# 'AppTrackingTransparency',
# 'BluetoothPeripheral',
# 'Calendars',
# 'Camera',
# 'Contacts',
# 'FaceID',
# 'LocationAccuracy',
# 'LocationAlways',
# 'LocationWhenInUse',
# 'MediaLibrary',
# 'Microphone',
# 'Motion',
# 'Notifications',
# 'PhotoLibrary',
# 'PhotoLibraryAddOnly',
# 'Reminders',
# 'SpeechRecognition',
# 'StoreKit'
])

#
```

3. Then execute `pod install` _(📌  Note that it must be re-executed each time you update this config)_.
4. Finally, update your `Info.plist` with the wanted permissions usage descriptions:

```xml
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -181,7 +210,7 @@ Open the project solution file from the `windows` folder. In the app project ope

## 🆘 Manual linking

Because this package targets React Native 0.63.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions. You also need to manual link the module on Windows when using React Native Windows prior to 0.63:
Because this package targets recent React Native versions, you probably don't need to link it manually. But if you have a special case, follow these additional instructions:

<details>
<summary><b>👀 See manual linking instructions</b></summary>
Expand Down Expand Up @@ -707,7 +736,7 @@ check(PERMISSIONS.IOS.LOCATION_ALWAYS)

Request one permission.

Note that the `rationale` parameter is only available and used on Android.
The `rationale` is only available and used on Android. It can be a native alert (a `Rationale` object) or a custom implementation (that resolves with a `boolean`).

```ts
type Rationale = {
Expand All @@ -718,7 +747,10 @@ type Rationale = {
buttonNeutral?: string;
};

function request(permission: string, rationale?: Rationale): Promise<PermissionStatus>;
function request(
permission: string,
rationale?: Rationale | (() => Promise<boolean>),
): Promise<PermissionStatus>;
```

```js
Expand Down
38 changes: 32 additions & 6 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# 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')

platform :ios, min_ios_version_supported
prepare_react_native_project!

setup_permissions([
'AppTrackingTransparency',
'BluetoothPeripheral',
'Calendars',
'Camera',
'Contacts',
'FaceID',
'LocationAccuracy',
'LocationAlways',
'LocationWhenInUse',
'MediaLibrary',
'Microphone',
'Motion',
'Notifications',
'PhotoLibrary',
'PhotoLibraryAddOnly',
'Reminders',
'SpeechRecognition',
'StoreKit'
])

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ PODS:
- React-jsi (= 0.72.4)
- React-logger (= 0.72.4)
- React-perflogger (= 0.72.4)
- RNPermissions (3.8.4):
- RNPermissions (3.9.0):
- React-Core
- RNVectorIcons (10.0.0):
- React-Core
Expand Down Expand Up @@ -720,12 +720,12 @@ SPEC CHECKSUMS:
React-runtimescheduler: 4941cc1b3cf08b792fbf666342c9fc95f1969035
React-utils: b79f2411931f9d3ea5781404dcbb2fa8a837e13a
ReactCommon: 4b2bdcb50a3543e1c2b2849ad44533686610826d
RNPermissions: ed00174a2d6efeff72f32af33332b28f64918e7c
RNPermissions: 535ef85ad2e77d65bc90ee2afcb734619cea6f56
RNVectorIcons: 8b5bb0fa61d54cd2020af4f24a51841ce365c7e9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 3efc43e0d48686ce2e8c60f99d4e6bd349aff981
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: fff8f587e10e262f18b440ce402f9b16a0fcafda
PODFILE CHECKSUM: d10907374d33d217871dd1ac7944e625d6d03f6c

COCOAPODS: 1.12.1
22 changes: 1 addition & 21 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,10 @@
"clean-modules": "rm -rf ./node_modules/react-native-permissions/{example,node_modules}",
"clean": "rm -rf ./node_modules ./ios/Pods",
"preinstall": "cd .. && yarn prepack && cd example",
"postinstall": "yarn clean-modules && react-native setup-ios-permissions && pod-install",
"postinstall": "yarn clean-modules && pod-install",
"start": "react-native start",
"reinstall": "yarn clean && yarn install"
},
"reactNativePermissionsIOS": [
"AppTrackingTransparency",
"BluetoothPeripheral",
"Calendars",
"Camera",
"Contacts",
"FaceID",
"LocationAccuracy",
"LocationAlways",
"LocationWhenInUse",
"MediaLibrary",
"Microphone",
"Motion",
"Notifications",
"PhotoLibrary",
"PhotoLibraryAddOnly",
"Reminders",
"SpeechRecognition",
"StoreKit"
],
"dependencies": {
"react": "18.2.0",
"react-native": "0.72.4",
Expand Down
10 changes: 0 additions & 10 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4621,13 +4621,6 @@ pkg-dir@^3.0.0:
dependencies:
find-up "^3.0.0"

pkg-dir@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-5.0.0.tgz#a02d6aebe6ba133a928f74aec20bafdfe6b8e760"
integrity sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==
dependencies:
find-up "^5.0.0"

[email protected]:
version "0.1.39"
resolved "https://registry.yarnpkg.com/pod-install/-/pod-install-0.1.39.tgz#853a0585bafbd332c2ca6543854fd4919958cfb3"
Expand Down Expand Up @@ -4740,9 +4733,6 @@ react-native-paper@^5.10.3:

react-native-permissions@../:
version "3.8.4"
dependencies:
picocolors "^1.0.0"
pkg-dir "^5.0.0"

react-native-safe-area-context@^4.7.1:
version "4.7.1"
Expand Down
2 changes: 1 addition & 1 deletion ios/RNPermissionsModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ - (NSDictionary *)constantsToExport {
NSMutableString *message = [NSMutableString new];

[message appendString:@"⚠ No permission handler detected.\n\n"];
[message appendString:@"• Check that you added at least one permission handler in your package.json reactNativePermissionsIOS config.\n"];
[message appendString:@"• Check that you are correctly calling setup_permissions in your Podfile.\n"];
[message appendString:@"• Uninstall this app, reinstall your Pods, delete your Xcode DerivedData folder and rebuild it.\n"];

RCTLogError(@"%@", message);
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-permissions",
"version": "3.8.4",
"version": "3.9.0",
"license": "MIT",
"description": "An unified permissions API for React Native on iOS, Android and Windows",
"author": "Mathieu Acthernoene <[email protected]>",
Expand All @@ -25,6 +25,7 @@
"!/android/build",
"/dist",
"/ios",
"/scripts",
"/windows",
"/src",
"/*.podspec",
Expand All @@ -33,7 +34,7 @@
],
"scripts": {
"format": "prettier '**/*' -u -w",
"lint": "eslint \"./**/*.{js,ts,tsx}\"",
"lint": "eslint './**/*.{js,ts,tsx}'",
"setup-hooks": "git config --local core.hooksPath .hooks",
"prepack": "bob build",
"typecheck": "tsc --project ./ --noEmit"
Expand Down Expand Up @@ -69,10 +70,6 @@
"optional": true
}
},
"dependencies": {
"picocolors": "^1.0.0",
"pkg-dir": "^5.0.0"
},
"devDependencies": {
"@types/react": "^18.2.21",
"@typescript-eslint/eslint-plugin": "^6.4.1",
Expand Down
Loading

0 comments on commit 3347278

Please sign in to comment.