or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdnotification-permissions.mdpermission-checking.mdpermission-constants.mdpermission-requesting.mdplatform-specific-features.md

permission-checking.mddocs/

0

# Permission Checking

1

2

Core functionality for checking the current status of device permissions. Returns status without requesting permission from the user.

3

4

## Capabilities

5

6

### Check Single Permission

7

8

Check the current status of a single permission without requesting it from the user.

9

10

```typescript { .api }

11

/**

12

* Check the current status of a single permission

13

* @param permission - The permission to check

14

* @returns Promise resolving to the current permission status

15

*/

16

function check(permission: Permission): Promise<PermissionStatus>;

17

```

18

19

**Usage Examples:**

20

21

```typescript

22

import { check, PERMISSIONS, RESULTS } from "react-native-permissions";

23

24

// Check camera permission on iOS

25

const cameraStatus = await check(PERMISSIONS.IOS.CAMERA);

26

if (cameraStatus === RESULTS.GRANTED) {

27

console.log("Camera permission is granted");

28

} else if (cameraStatus === RESULTS.DENIED) {

29

console.log("Camera permission is denied");

30

} else if (cameraStatus === RESULTS.BLOCKED) {

31

console.log("Camera permission is permanently blocked");

32

}

33

34

// Check location permission on Android

35

const locationStatus = await check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);

36

console.log("Location permission status:", locationStatus);

37

```

38

39

### Check Multiple Permissions

40

41

Check the status of multiple permissions in a single call, returning a mapped object with each permission's status.

42

43

```typescript { .api }

44

/**

45

* Check the status of multiple permissions simultaneously

46

* @param permissions - Array of permissions to check

47

* @returns Promise resolving to object mapping each permission to its status

48

*/

49

function checkMultiple<P extends Permission[]>(

50

permissions: P

51

): Promise<Record<P[number], PermissionStatus>>;

52

```

53

54

**Usage Examples:**

55

56

```typescript

57

import { checkMultiple, PERMISSIONS, RESULTS } from "react-native-permissions";

58

59

// Check multiple iOS permissions

60

const statuses = await checkMultiple([

61

PERMISSIONS.IOS.CAMERA,

62

PERMISSIONS.IOS.MICROPHONE,

63

PERMISSIONS.IOS.PHOTO_LIBRARY,

64

]);

65

66

console.log("Camera:", statuses[PERMISSIONS.IOS.CAMERA]);

67

console.log("Microphone:", statuses[PERMISSIONS.IOS.MICROPHONE]);

68

console.log("Photo Library:", statuses[PERMISSIONS.IOS.PHOTO_LIBRARY]);

69

70

// Check if all permissions are granted

71

const allGranted = Object.values(statuses).every(status => status === RESULTS.GRANTED);

72

console.log("All permissions granted:", allGranted);

73

74

// Check specific Android permissions

75

const androidStatuses = await checkMultiple([

76

PERMISSIONS.ANDROID.CAMERA,

77

PERMISSIONS.ANDROID.RECORD_AUDIO,

78

PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE,

79

]);

80

```

81

82

### Check Location Accuracy (iOS)

83

84

Check the current location accuracy authorization level on iOS devices.

85

86

```typescript { .api }

87

/**

88

* Check the current location accuracy authorization (iOS only)

89

* @returns Promise resolving to current location accuracy level

90

*/

91

function checkLocationAccuracy(): Promise<LocationAccuracy>;

92

93

type LocationAccuracy = 'full' | 'reduced';

94

```

95

96

**Usage Examples:**

97

98

```typescript

99

import { checkLocationAccuracy, PERMISSIONS, check } from "react-native-permissions";

100

101

// First ensure location permission is granted

102

const locationStatus = await check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);

103

if (locationStatus === RESULTS.GRANTED) {

104

const accuracy = await checkLocationAccuracy();

105

if (accuracy === 'full') {

106

console.log("Full location accuracy available");

107

} else {

108

console.log("Reduced location accuracy - consider requesting full accuracy");

109

}

110

}

111

```

112

113

### Check Notification Permissions

114

115

Check notification permissions and get detailed settings for each notification type.

116

117

```typescript { .api }

118

/**

119

* Check notification permissions and get detailed settings

120

* @returns Promise resolving to notification status and settings

121

*/

122

function checkNotifications(): Promise<NotificationsResponse>;

123

124

interface NotificationsResponse {

125

status: PermissionStatus;

126

settings: NotificationSettings;

127

}

128

129

interface NotificationSettings {

130

alert?: boolean;

131

badge?: boolean;

132

sound?: boolean;

133

carPlay?: boolean;

134

criticalAlert?: boolean;

135

provisional?: boolean;

136

providesAppSettings?: boolean;

137

lockScreen?: boolean;

138

notificationCenter?: boolean;

139

}

140

```

141

142

**Usage Examples:**

143

144

```typescript

145

import { checkNotifications, RESULTS } from "react-native-permissions";

146

147

const notificationResult = await checkNotifications();

148

149

console.log("Notification status:", notificationResult.status);

150

151

if (notificationResult.status === RESULTS.GRANTED) {

152

const { settings } = notificationResult;

153

console.log("Alert notifications:", settings.alert);

154

console.log("Badge notifications:", settings.badge);

155

console.log("Sound notifications:", settings.sound);

156

console.log("Lock screen notifications:", settings.lockScreen);

157

}

158

159

// Check if specific notification types are enabled

160

if (notificationResult.settings.alert && notificationResult.settings.sound) {

161

console.log("Both alert and sound notifications are enabled");

162

}

163

```

164

165

## Permission Status Values

166

167

All check functions return one of these permission status values:

168

169

```typescript { .api }

170

type PermissionStatus = 'unavailable' | 'blocked' | 'denied' | 'granted' | 'limited';

171

172

// Available as constants:

173

declare const RESULTS: {

174

readonly UNAVAILABLE: 'unavailable'; // Permission not available on this platform

175

readonly BLOCKED: 'blocked'; // Permission permanently denied

176

readonly DENIED: 'denied'; // Permission denied but can be requested again

177

readonly GRANTED: 'granted'; // Permission granted

178

readonly LIMITED: 'limited'; // Permission granted with limitations (iOS)

179

};

180

```

181

182

## Error Handling

183

184

Check functions may throw errors in the following cases:

185

186

- **Invalid Permission**: When checking a permission not available on the current platform

187

- **Native Module Error**: When the native module fails to initialize or respond

188

- **Platform Unsupported**: When calling platform-specific methods on unsupported platforms

189

190

```typescript

191

import { check, PERMISSIONS } from "react-native-permissions";

192

193

try {

194

const status = await check(PERMISSIONS.IOS.CAMERA);

195

console.log("Permission status:", status);

196

} catch (error) {

197

console.error("Failed to check permission:", error);

198

// Handle error appropriately

199

}

200

```