Skip to content

Commit

Permalink
Add react-native setup-ios-permissions command (zoontek#750)
Browse files Browse the repository at this point in the history
* Add setup-ios-permissions command

* Improve wording

* Update description

* Remove warning emoji

* Update config key

* Add support for .mm files (new architecture)

* Remove mention of the workaround

* Update documentation

* Remove cache mention

* Bump version number
  • Loading branch information
zoontek authored Feb 26, 2023
1 parent c22eb85 commit 8e7c47d
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 250 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ example/
fetchWindowsCapabilites.js
mock.js
node_modules
react-native.config.js
39 changes: 0 additions & 39 deletions MIGRATION.md

This file was deleted.

89 changes: 34 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,42 @@ $ yarn add react-native-permissions

### iOS

By default no permission handler is installed. Update your `Podfile` by choosing the ones you want to check or request, then run `pod install`.

```ruby
target 'YourAwesomeProject' do

#

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

pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
pod 'Permission-Motion', :path => "#{permissions_path}/Motion"
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
pod 'Permission-Siri', :path => "#{permissions_path}/Siri"
pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"
pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit"

end
By default no permission handler is installed. 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`.

_📌  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"
}
}
```

> :warning: If you see a **No permission handler detected** error: Make sure that you have at least one permission handler set up. In some cases the Xcode cache needs to be cleared (`Xcode -> Product -> Clean Build Folder`)
Then update your `Info.plist` with wanted permissions usage descriptions:

```xml
Expand Down Expand Up @@ -129,29 +131,6 @@ Then update your `Info.plist` with wanted permissions usage descriptions:
</plist>
```

#### Workaround for `use_frameworks!` issues

If you use `use_frameworks!`, add this at the top of your `Podfile`, and uncomment the line corresponding to your CocoaPods version:

```ruby
use_frameworks!

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

### Android

Add all wanted permissions to your app `android/app/src/main/AndroidManifest.xml` file:
Expand Down
2 changes: 1 addition & 1 deletion RNPermissions.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.source = { :git => package["repository"]["url"], :tag => s.version }
s.source_files = "ios/*.{h,m}"
s.source_files = "ios/*.{h,m,mm}"
end
39 changes: 0 additions & 39 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@ if linkage != nil
use_frameworks! :linkage => linkage.to_sym
end

# use_frameworks!

# # 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 one line depending on your CocoaPods version
# # Pod::BuildType.static_library # >= 1.9
# # Pod::Target::BuildType.static_library # < 1.9
# end
# end
# end
# end

target 'RNPermissionsExample' do
config = use_native_modules!

Expand All @@ -60,28 +43,6 @@ target 'RNPermissionsExample' do
:app_path => "#{Pod::Config.instance.installation_root}/.."
)

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

pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
pod 'Permission-Motion', :path => "#{permissions_path}/Motion"
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
# pod 'Permission-Siri', :path => "#{permissions_path}/Siri"
pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"
pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit"

post_install do |installer|
react_native_post_install(
installer,
Expand Down
114 changes: 3 additions & 111 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,6 @@ PODS:
- hermes-engine/Pre-built (0.71.3)
- libevent (2.1.12)
- OpenSSL-Universal (1.1.1100)
- Permission-AppTrackingTransparency (3.6.1):
- RNPermissions
- Permission-BluetoothPeripheral (3.6.1):
- RNPermissions
- Permission-Calendars (3.6.1):
- RNPermissions
- Permission-Camera (3.6.1):
- RNPermissions
- Permission-Contacts (3.6.1):
- RNPermissions
- Permission-FaceID (3.6.1):
- RNPermissions
- Permission-LocationAccuracy (3.6.1):
- RNPermissions
- Permission-LocationAlways (3.6.1):
- RNPermissions
- Permission-LocationWhenInUse (3.6.1):
- RNPermissions
- Permission-MediaLibrary (3.6.1):
- RNPermissions
- Permission-Microphone (3.6.1):
- RNPermissions
- Permission-Motion (3.6.1):
- RNPermissions
- Permission-Notifications (3.6.1):
- RNPermissions
- Permission-PhotoLibrary (3.6.1):
- RNPermissions
- Permission-PhotoLibraryAddOnly (3.6.1):
- RNPermissions
- Permission-Reminders (3.6.1):
- RNPermissions
- Permission-SpeechRecognition (3.6.1):
- RNPermissions
- Permission-StoreKit (3.6.1):
- RNPermissions
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -455,7 +419,7 @@ PODS:
- React-jsi (= 0.71.3)
- React-logger (= 0.71.3)
- React-perflogger (= 0.71.3)
- RNPermissions (3.6.1):
- RNPermissions (3.7.0):
- React-Core
- RNVectorIcons (9.2.0):
- React-Core
Expand Down Expand Up @@ -494,24 +458,6 @@ DEPENDENCIES:
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- libevent (~> 2.1.12)
- OpenSSL-Universal (= 1.1.1100)
- Permission-AppTrackingTransparency (from `../node_modules/react-native-permissions/ios/AppTrackingTransparency`)
- Permission-BluetoothPeripheral (from `../node_modules/react-native-permissions/ios/BluetoothPeripheral`)
- Permission-Calendars (from `../node_modules/react-native-permissions/ios/Calendars`)
- Permission-Camera (from `../node_modules/react-native-permissions/ios/Camera`)
- Permission-Contacts (from `../node_modules/react-native-permissions/ios/Contacts`)
- Permission-FaceID (from `../node_modules/react-native-permissions/ios/FaceID`)
- Permission-LocationAccuracy (from `../node_modules/react-native-permissions/ios/LocationAccuracy`)
- Permission-LocationAlways (from `../node_modules/react-native-permissions/ios/LocationAlways`)
- Permission-LocationWhenInUse (from `../node_modules/react-native-permissions/ios/LocationWhenInUse`)
- Permission-MediaLibrary (from `../node_modules/react-native-permissions/ios/MediaLibrary`)
- Permission-Microphone (from `../node_modules/react-native-permissions/ios/Microphone`)
- Permission-Motion (from `../node_modules/react-native-permissions/ios/Motion`)
- Permission-Notifications (from `../node_modules/react-native-permissions/ios/Notifications`)
- Permission-PhotoLibrary (from `../node_modules/react-native-permissions/ios/PhotoLibrary`)
- Permission-PhotoLibraryAddOnly (from `../node_modules/react-native-permissions/ios/PhotoLibraryAddOnly`)
- Permission-Reminders (from `../node_modules/react-native-permissions/ios/Reminders`)
- Permission-SpeechRecognition (from `../node_modules/react-native-permissions/ios/SpeechRecognition`)
- Permission-StoreKit (from `../node_modules/react-native-permissions/ios/StoreKit`)
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
Expand Down Expand Up @@ -577,42 +523,6 @@ EXTERNAL SOURCES:
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
Permission-AppTrackingTransparency:
:path: "../node_modules/react-native-permissions/ios/AppTrackingTransparency"
Permission-BluetoothPeripheral:
:path: "../node_modules/react-native-permissions/ios/BluetoothPeripheral"
Permission-Calendars:
:path: "../node_modules/react-native-permissions/ios/Calendars"
Permission-Camera:
:path: "../node_modules/react-native-permissions/ios/Camera"
Permission-Contacts:
:path: "../node_modules/react-native-permissions/ios/Contacts"
Permission-FaceID:
:path: "../node_modules/react-native-permissions/ios/FaceID"
Permission-LocationAccuracy:
:path: "../node_modules/react-native-permissions/ios/LocationAccuracy"
Permission-LocationAlways:
:path: "../node_modules/react-native-permissions/ios/LocationAlways"
Permission-LocationWhenInUse:
:path: "../node_modules/react-native-permissions/ios/LocationWhenInUse"
Permission-MediaLibrary:
:path: "../node_modules/react-native-permissions/ios/MediaLibrary"
Permission-Microphone:
:path: "../node_modules/react-native-permissions/ios/Microphone"
Permission-Motion:
:path: "../node_modules/react-native-permissions/ios/Motion"
Permission-Notifications:
:path: "../node_modules/react-native-permissions/ios/Notifications"
Permission-PhotoLibrary:
:path: "../node_modules/react-native-permissions/ios/PhotoLibrary"
Permission-PhotoLibraryAddOnly:
:path: "../node_modules/react-native-permissions/ios/PhotoLibraryAddOnly"
Permission-Reminders:
:path: "../node_modules/react-native-permissions/ios/Reminders"
Permission-SpeechRecognition:
:path: "../node_modules/react-native-permissions/ios/SpeechRecognition"
Permission-StoreKit:
:path: "../node_modules/react-native-permissions/ios/StoreKit"
RCT-Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
RCTRequired:
Expand Down Expand Up @@ -696,24 +606,6 @@ SPEC CHECKSUMS:
hermes-engine: 38bfe887e456b33b697187570a08de33969f5db7
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Permission-AppTrackingTransparency: 9eedbc3b5a2907b8cb2c971461754616eac1661d
Permission-BluetoothPeripheral: 67708853584bb9208c76d36d0e0ea4eafb97ea5b
Permission-Calendars: dd55f36958c398a487f141d4c89119907e34dca8
Permission-Camera: bf6791b17c7f614b6826019fcfdcc286d3a107f6
Permission-Contacts: 2484d274171688b1ca80978b949ac771259b51f0
Permission-FaceID: e70223280292a1a5e4b8ad943b70cd9229a7d2c3
Permission-LocationAccuracy: 76df17de5c6b8bc2eee34e61ee92cdd7a864c73d
Permission-LocationAlways: 8d99b025c9f73c696e0cdb367e42525f2e9a26f2
Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4
Permission-MediaLibrary: a994236bae41b3597a376ff08298fb1c6d84729b
Permission-Microphone: 48212dd4d28025d9930d583e3c7a56da7268665c
Permission-Motion: d3e5ac6c989b2594a3c5c5ab19ffe9453fa3eb5c
Permission-Notifications: 150484ae586eb9be4e32217582a78350a9bb31c3
Permission-PhotoLibrary: 5b34ca67279f7201ae109cef36f9806a6596002d
Permission-PhotoLibraryAddOnly: 6dba8924024e239af2e282daa8a88967679b4983
Permission-Reminders: dd6692dab69ae8a4e2473860e25b6304f9bcd326
Permission-SpeechRecognition: 7bda51c7a3b68f259a98436ed431afdf84a19ecf
Permission-StoreKit: 7dcf43ad1b8cdc7ae21e547d49df9ac9b6ea7270
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: bec48f07daf7bcdc2655a0cde84e07d24d2a9e2a
RCTTypeSafety: 171394eebacf71e1cfad79dbfae7ee8fc16ca80a
Expand Down Expand Up @@ -742,12 +634,12 @@ SPEC CHECKSUMS:
React-RCTVibration: 5199a180d04873366a83855de55ac33ce60fe4d5
React-runtimeexecutor: 7bf0dafc7b727d93c8cb94eb00a9d3753c446c3e
ReactCommon: 6f65ea5b7d84deb9e386f670dd11ce499ded7b40
RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c
RNPermissions: 2874f8dbcfb95a6079a98e19dcc5767e086bc77d
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: 5ed1699acbba8863755998a4245daa200ff3817b
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 31bbb3fdb2c3b3bc787b7409362c73d1b56d9e38
PODFILE CHECKSUM: 2de9221df73fac717714236687b9875bb50f8f18

COCOAPODS: 1.11.3
Loading

0 comments on commit 8e7c47d

Please sign in to comment.