Mathieu Acthernoene 5 years ago
parent
commit
54ac46fce0
1 changed files with 22 additions and 8 deletions
  1. 22
    8
      src/index.ts

+ 22
- 8
src/index.ts View File

98
 }
98
 }
99
 
99
 
100
 const RNPermissions: {
100
 const RNPermissions: {
101
-  openSettings: () => Promise<true>;
102
-  check: (permission: Permission) => Promise<PermissionStatus>;
103
-  request: (
104
-    permission: Permission,
105
-    rationale?: Rationale,
106
-  ) => Promise<PermissionStatus>;
101
+  // Android + iOS
107
   checkNotifications: () => Promise<NotificationsResponse>;
102
   checkNotifications: () => Promise<NotificationsResponse>;
108
   requestNotifications: (
103
   requestNotifications: (
109
     options: NotificationOption[],
104
     options: NotificationOption[],
110
   ) => Promise<NotificationsResponse>;
105
   ) => Promise<NotificationsResponse>;
106
+  openSettings: () => Promise<true>;
111
 
107
 
112
-  // android only module methods
108
+  // Android only
113
   isAvailable: (permission: Permission) => Promise<boolean>;
109
   isAvailable: (permission: Permission) => Promise<boolean>;
114
-  setNonRequestable: (permission: Permission) => Promise<true>;
115
   getNonRequestables: () => Promise<Permission[]>;
110
   getNonRequestables: () => Promise<Permission[]>;
111
+  setNonRequestable: (permission: Permission) => Promise<true>;
112
+
113
+  // iOS only
114
+  check: (permission: Permission) => Promise<PermissionStatus>;
115
+  request: (
116
+    permission: Permission,
117
+    rationale?: Rationale,
118
+  ) => Promise<PermissionStatus>;
116
 } = NativeModules.RNPermissions;
119
 } = NativeModules.RNPermissions;
117
 
120
 
121
+// Produce an error if we don't have the native module
122
+if (RNPermissions == null) {
123
+  throw new Error(`react-native-permissions: NativeModule.RNPermissions is null. To fix this issue try these steps:
124
+• Run \`react-native link react-native-permissions\` in the project root.
125
+• Rebuild and re-run the app.
126
+• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
127
+• Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.
128
+* If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README.
129
+If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-permissions`);
130
+}
131
+
118
 const platformPermissions = Object.values(
132
 const platformPermissions = Object.values(
119
   Platform.OS === 'ios' ? IOS : ANDROID,
133
   Platform.OS === 'ios' ? IOS : ANDROID,
120
 );
134
 );