Skip to content

Commit 8e7c47d

Browse files
authored
Add react-native setup-ios-permissions command (#750)
* 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
1 parent c22eb85 commit 8e7c47d

File tree

12 files changed

+213
-250
lines changed

12 files changed

+213
-250
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ example/
44
fetchWindowsCapabilites.js
55
mock.js
66
node_modules
7+
react-native.config.js

MIGRATION.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

README.md

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,42 @@ $ yarn add react-native-permissions
3737

3838
### iOS
3939

40-
By default no permission handler is installed. Update your `Podfile` by choosing the ones you want to check or request, then run `pod install`.
41-
42-
```ruby
43-
target 'YourAwesomeProject' do
44-
45-
#
46-
47-
permissions_path = '../node_modules/react-native-permissions/ios'
48-
49-
pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
50-
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
51-
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
52-
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
53-
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
54-
pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
55-
pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
56-
pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
57-
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
58-
pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
59-
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
60-
pod 'Permission-Motion', :path => "#{permissions_path}/Motion"
61-
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
62-
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
63-
pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
64-
pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
65-
pod 'Permission-Siri', :path => "#{permissions_path}/Siri"
66-
pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"
67-
pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit"
68-
69-
end
40+
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`.
41+
42+
_📌  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._
43+
44+
```json
45+
{
46+
"reactNativePermissionsIOS": [
47+
"AppTrackingTransparency",
48+
"BluetoothPeripheral",
49+
"Calendars",
50+
"Camera",
51+
"Contacts",
52+
"FaceID",
53+
"LocationAccuracy",
54+
"LocationAlways",
55+
"LocationWhenInUse",
56+
"MediaLibrary",
57+
"Microphone",
58+
"Motion",
59+
"Notifications",
60+
"PhotoLibrary",
61+
"PhotoLibraryAddOnly",
62+
"Reminders",
63+
"Siri",
64+
"SpeechRecognition",
65+
"StoreKit"
66+
],
67+
"devDependencies": {
68+
"pod-install": "0.1.38"
69+
},
70+
"scripts": {
71+
"postinstall": "react-native setup-ios-permissions && pod-install"
72+
}
73+
}
7074
```
7175

72-
> :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`)
73-
7476
Then update your `Info.plist` with wanted permissions usage descriptions:
7577

7678
```xml
@@ -129,29 +131,6 @@ Then update your `Info.plist` with wanted permissions usage descriptions:
129131
</plist>
130132
```
131133

132-
#### Workaround for `use_frameworks!` issues
133-
134-
If you use `use_frameworks!`, add this at the top of your `Podfile`, and uncomment the line corresponding to your CocoaPods version:
135-
136-
```ruby
137-
use_frameworks!
138-
139-
# Convert all permission pods into static libraries
140-
pre_install do |installer|
141-
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
142-
143-
installer.pod_targets.each do |pod|
144-
if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
145-
def pod.build_type;
146-
# Uncomment the line corresponding to your CocoaPods version
147-
# Pod::BuildType.static_library # >= 1.9
148-
# Pod::Target::BuildType.static_library # < 1.9
149-
end
150-
end
151-
end
152-
end
153-
```
154-
155134
### Android
156135

157136
Add all wanted permissions to your app `android/app/src/main/AndroidManifest.xml` file:

RNPermissions.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
1616
s.requires_arc = true
1717

1818
s.source = { :git => package["repository"]["url"], :tag => s.version }
19-
s.source_files = "ios/*.{h,m}"
19+
s.source_files = "ios/*.{h,m,mm}"
2020
end

example/ios/Podfile

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,6 @@ if linkage != nil
2121
use_frameworks! :linkage => linkage.to_sym
2222
end
2323

24-
# use_frameworks!
25-
26-
# # Convert all permission pods into static libraries
27-
# pre_install do |installer|
28-
# Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
29-
30-
# installer.pod_targets.each do |pod|
31-
# if pod.name.eql?('RNPermissions') || pod.name.start_with?('Permission-')
32-
# def pod.build_type;
33-
# # Uncomment one line depending on your CocoaPods version
34-
# # Pod::BuildType.static_library # >= 1.9
35-
# # Pod::Target::BuildType.static_library # < 1.9
36-
# end
37-
# end
38-
# end
39-
# end
40-
4124
target 'RNPermissionsExample' do
4225
config = use_native_modules!
4326

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

63-
permissions_path = '../node_modules/react-native-permissions/ios'
64-
65-
pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency"
66-
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"
67-
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars"
68-
pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
69-
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts"
70-
pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID"
71-
pod 'Permission-LocationAccuracy', :path => "#{permissions_path}/LocationAccuracy"
72-
pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways"
73-
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
74-
pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary"
75-
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
76-
pod 'Permission-Motion', :path => "#{permissions_path}/Motion"
77-
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications"
78-
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"
79-
pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly"
80-
pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders"
81-
# pod 'Permission-Siri', :path => "#{permissions_path}/Siri"
82-
pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition"
83-
pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit"
84-
8546
post_install do |installer|
8647
react_native_post_install(
8748
installer,

example/ios/Podfile.lock

Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -78,42 +78,6 @@ PODS:
7878
- hermes-engine/Pre-built (0.71.3)
7979
- libevent (2.1.12)
8080
- OpenSSL-Universal (1.1.1100)
81-
- Permission-AppTrackingTransparency (3.6.1):
82-
- RNPermissions
83-
- Permission-BluetoothPeripheral (3.6.1):
84-
- RNPermissions
85-
- Permission-Calendars (3.6.1):
86-
- RNPermissions
87-
- Permission-Camera (3.6.1):
88-
- RNPermissions
89-
- Permission-Contacts (3.6.1):
90-
- RNPermissions
91-
- Permission-FaceID (3.6.1):
92-
- RNPermissions
93-
- Permission-LocationAccuracy (3.6.1):
94-
- RNPermissions
95-
- Permission-LocationAlways (3.6.1):
96-
- RNPermissions
97-
- Permission-LocationWhenInUse (3.6.1):
98-
- RNPermissions
99-
- Permission-MediaLibrary (3.6.1):
100-
- RNPermissions
101-
- Permission-Microphone (3.6.1):
102-
- RNPermissions
103-
- Permission-Motion (3.6.1):
104-
- RNPermissions
105-
- Permission-Notifications (3.6.1):
106-
- RNPermissions
107-
- Permission-PhotoLibrary (3.6.1):
108-
- RNPermissions
109-
- Permission-PhotoLibraryAddOnly (3.6.1):
110-
- RNPermissions
111-
- Permission-Reminders (3.6.1):
112-
- RNPermissions
113-
- Permission-SpeechRecognition (3.6.1):
114-
- RNPermissions
115-
- Permission-StoreKit (3.6.1):
116-
- RNPermissions
11781
- RCT-Folly (2021.07.22.00):
11882
- boost
11983
- DoubleConversion
@@ -455,7 +419,7 @@ PODS:
455419
- React-jsi (= 0.71.3)
456420
- React-logger (= 0.71.3)
457421
- React-perflogger (= 0.71.3)
458-
- RNPermissions (3.6.1):
422+
- RNPermissions (3.7.0):
459423
- React-Core
460424
- RNVectorIcons (9.2.0):
461425
- React-Core
@@ -494,24 +458,6 @@ DEPENDENCIES:
494458
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
495459
- libevent (~> 2.1.12)
496460
- OpenSSL-Universal (= 1.1.1100)
497-
- Permission-AppTrackingTransparency (from `../node_modules/react-native-permissions/ios/AppTrackingTransparency`)
498-
- Permission-BluetoothPeripheral (from `../node_modules/react-native-permissions/ios/BluetoothPeripheral`)
499-
- Permission-Calendars (from `../node_modules/react-native-permissions/ios/Calendars`)
500-
- Permission-Camera (from `../node_modules/react-native-permissions/ios/Camera`)
501-
- Permission-Contacts (from `../node_modules/react-native-permissions/ios/Contacts`)
502-
- Permission-FaceID (from `../node_modules/react-native-permissions/ios/FaceID`)
503-
- Permission-LocationAccuracy (from `../node_modules/react-native-permissions/ios/LocationAccuracy`)
504-
- Permission-LocationAlways (from `../node_modules/react-native-permissions/ios/LocationAlways`)
505-
- Permission-LocationWhenInUse (from `../node_modules/react-native-permissions/ios/LocationWhenInUse`)
506-
- Permission-MediaLibrary (from `../node_modules/react-native-permissions/ios/MediaLibrary`)
507-
- Permission-Microphone (from `../node_modules/react-native-permissions/ios/Microphone`)
508-
- Permission-Motion (from `../node_modules/react-native-permissions/ios/Motion`)
509-
- Permission-Notifications (from `../node_modules/react-native-permissions/ios/Notifications`)
510-
- Permission-PhotoLibrary (from `../node_modules/react-native-permissions/ios/PhotoLibrary`)
511-
- Permission-PhotoLibraryAddOnly (from `../node_modules/react-native-permissions/ios/PhotoLibraryAddOnly`)
512-
- Permission-Reminders (from `../node_modules/react-native-permissions/ios/Reminders`)
513-
- Permission-SpeechRecognition (from `../node_modules/react-native-permissions/ios/SpeechRecognition`)
514-
- Permission-StoreKit (from `../node_modules/react-native-permissions/ios/StoreKit`)
515461
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
516462
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
517463
- RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`)
@@ -577,42 +523,6 @@ EXTERNAL SOURCES:
577523
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
578524
hermes-engine:
579525
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
580-
Permission-AppTrackingTransparency:
581-
:path: "../node_modules/react-native-permissions/ios/AppTrackingTransparency"
582-
Permission-BluetoothPeripheral:
583-
:path: "../node_modules/react-native-permissions/ios/BluetoothPeripheral"
584-
Permission-Calendars:
585-
:path: "../node_modules/react-native-permissions/ios/Calendars"
586-
Permission-Camera:
587-
:path: "../node_modules/react-native-permissions/ios/Camera"
588-
Permission-Contacts:
589-
:path: "../node_modules/react-native-permissions/ios/Contacts"
590-
Permission-FaceID:
591-
:path: "../node_modules/react-native-permissions/ios/FaceID"
592-
Permission-LocationAccuracy:
593-
:path: "../node_modules/react-native-permissions/ios/LocationAccuracy"
594-
Permission-LocationAlways:
595-
:path: "../node_modules/react-native-permissions/ios/LocationAlways"
596-
Permission-LocationWhenInUse:
597-
:path: "../node_modules/react-native-permissions/ios/LocationWhenInUse"
598-
Permission-MediaLibrary:
599-
:path: "../node_modules/react-native-permissions/ios/MediaLibrary"
600-
Permission-Microphone:
601-
:path: "../node_modules/react-native-permissions/ios/Microphone"
602-
Permission-Motion:
603-
:path: "../node_modules/react-native-permissions/ios/Motion"
604-
Permission-Notifications:
605-
:path: "../node_modules/react-native-permissions/ios/Notifications"
606-
Permission-PhotoLibrary:
607-
:path: "../node_modules/react-native-permissions/ios/PhotoLibrary"
608-
Permission-PhotoLibraryAddOnly:
609-
:path: "../node_modules/react-native-permissions/ios/PhotoLibraryAddOnly"
610-
Permission-Reminders:
611-
:path: "../node_modules/react-native-permissions/ios/Reminders"
612-
Permission-SpeechRecognition:
613-
:path: "../node_modules/react-native-permissions/ios/SpeechRecognition"
614-
Permission-StoreKit:
615-
:path: "../node_modules/react-native-permissions/ios/StoreKit"
616526
RCT-Folly:
617527
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
618528
RCTRequired:
@@ -696,24 +606,6 @@ SPEC CHECKSUMS:
696606
hermes-engine: 38bfe887e456b33b697187570a08de33969f5db7
697607
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
698608
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
699-
Permission-AppTrackingTransparency: 9eedbc3b5a2907b8cb2c971461754616eac1661d
700-
Permission-BluetoothPeripheral: 67708853584bb9208c76d36d0e0ea4eafb97ea5b
701-
Permission-Calendars: dd55f36958c398a487f141d4c89119907e34dca8
702-
Permission-Camera: bf6791b17c7f614b6826019fcfdcc286d3a107f6
703-
Permission-Contacts: 2484d274171688b1ca80978b949ac771259b51f0
704-
Permission-FaceID: e70223280292a1a5e4b8ad943b70cd9229a7d2c3
705-
Permission-LocationAccuracy: 76df17de5c6b8bc2eee34e61ee92cdd7a864c73d
706-
Permission-LocationAlways: 8d99b025c9f73c696e0cdb367e42525f2e9a26f2
707-
Permission-LocationWhenInUse: 3ba99e45c852763f730eabecec2870c2382b7bd4
708-
Permission-MediaLibrary: a994236bae41b3597a376ff08298fb1c6d84729b
709-
Permission-Microphone: 48212dd4d28025d9930d583e3c7a56da7268665c
710-
Permission-Motion: d3e5ac6c989b2594a3c5c5ab19ffe9453fa3eb5c
711-
Permission-Notifications: 150484ae586eb9be4e32217582a78350a9bb31c3
712-
Permission-PhotoLibrary: 5b34ca67279f7201ae109cef36f9806a6596002d
713-
Permission-PhotoLibraryAddOnly: 6dba8924024e239af2e282daa8a88967679b4983
714-
Permission-Reminders: dd6692dab69ae8a4e2473860e25b6304f9bcd326
715-
Permission-SpeechRecognition: 7bda51c7a3b68f259a98436ed431afdf84a19ecf
716-
Permission-StoreKit: 7dcf43ad1b8cdc7ae21e547d49df9ac9b6ea7270
717609
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
718610
RCTRequired: bec48f07daf7bcdc2655a0cde84e07d24d2a9e2a
719611
RCTTypeSafety: 171394eebacf71e1cfad79dbfae7ee8fc16ca80a
@@ -742,12 +634,12 @@ SPEC CHECKSUMS:
742634
React-RCTVibration: 5199a180d04873366a83855de55ac33ce60fe4d5
743635
React-runtimeexecutor: 7bf0dafc7b727d93c8cb94eb00a9d3753c446c3e
744636
ReactCommon: 6f65ea5b7d84deb9e386f670dd11ce499ded7b40
745-
RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c
637+
RNPermissions: 2874f8dbcfb95a6079a98e19dcc5767e086bc77d
746638
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
747639
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
748640
Yoga: 5ed1699acbba8863755998a4245daa200ff3817b
749641
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
750642

751-
PODFILE CHECKSUM: 31bbb3fdb2c3b3bc787b7409362c73d1b56d9e38
643+
PODFILE CHECKSUM: 2de9221df73fac717714236687b9875bb50f8f18
752644

753645
COCOAPODS: 1.11.3

0 commit comments

Comments
 (0)