瀏覽代碼

Commit new native modules

Mathieu Acthernoene 5 年之前
父節點
當前提交
bfa5993ca9
共有 76 個文件被更改,包括 1957 次插入1713 次删除
  1. 59
    3
      .flowconfig
  2. 54
    9
      .gitignore
  3. 25
    0
      android/build.gradle
  4. 4
    0
      android/src/main/AndroidManifest.xml
  5. 52
    0
      android/src/main/java/com/yonahforst/rnpermissions/RNPermissionsModule.java
  6. 23
    0
      android/src/main/java/com/yonahforst/rnpermissions/RNPermissionsPackage.java
  7. 2
    2
      index.js
  8. 5
    0
      ios/PermissionHandlers/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.h
  9. 66
    0
      ios/PermissionHandlers/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m
  10. 5
    0
      ios/PermissionHandlers/Calendars/RNPermissionHandlerCalendars.h
  11. 37
    0
      ios/PermissionHandlers/Calendars/RNPermissionHandlerCalendars.m
  12. 5
    0
      ios/PermissionHandlers/Camera/RNPermissionHandlerCamera.h
  13. 33
    0
      ios/PermissionHandlers/Camera/RNPermissionHandlerCamera.m
  14. 5
    0
      ios/PermissionHandlers/Contacts/RNPermissionHandlerContacts.h
  15. 37
    0
      ios/PermissionHandlers/Contacts/RNPermissionHandlerContacts.m
  16. 5
    0
      ios/PermissionHandlers/FaceID/RNPermissionHandlerFaceID.h
  17. 75
    0
      ios/PermissionHandlers/FaceID/RNPermissionHandlerFaceID.m
  18. 5
    0
      ios/PermissionHandlers/LocationAlways/RNPermissionHandlerLocationAlways.h
  19. 88
    0
      ios/PermissionHandlers/LocationAlways/RNPermissionHandlerLocationAlways.m
  20. 5
    0
      ios/PermissionHandlers/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.h
  21. 65
    0
      ios/PermissionHandlers/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.m
  22. 5
    0
      ios/PermissionHandlers/MediaLibrary/RNPermissionHandlerMediaLibrary.h
  23. 41
    0
      ios/PermissionHandlers/MediaLibrary/RNPermissionHandlerMediaLibrary.m
  24. 5
    0
      ios/PermissionHandlers/Microphone/RNPermissionHandlerMicrophone.h
  25. 33
    0
      ios/PermissionHandlers/Microphone/RNPermissionHandlerMicrophone.m
  26. 5
    0
      ios/PermissionHandlers/Motion/RNPermissionHandlerMotion.h
  27. 74
    0
      ios/PermissionHandlers/Motion/RNPermissionHandlerMotion.m
  28. 5
    0
      ios/PermissionHandlers/Notifications/RNPermissionHandlerNotifications.h
  29. 98
    0
      ios/PermissionHandlers/Notifications/RNPermissionHandlerNotifications.m
  30. 5
    0
      ios/PermissionHandlers/PhotoLibrary/RNPermissionHandlerPhotoLibrary.h
  31. 33
    0
      ios/PermissionHandlers/PhotoLibrary/RNPermissionHandlerPhotoLibrary.m
  32. 5
    0
      ios/PermissionHandlers/Reminders/RNPermissionHandlerReminders.h
  33. 37
    0
      ios/PermissionHandlers/Reminders/RNPermissionHandlerReminders.m
  34. 5
    0
      ios/PermissionHandlers/Siri/RNPermissionHandlerSiri.h
  35. 41
    0
      ios/PermissionHandlers/Siri/RNPermissionHandlerSiri.m
  36. 5
    0
      ios/PermissionHandlers/SpeechRecognition/RNPermissionHandlerSpeechRecognition.h
  37. 41
    0
      ios/PermissionHandlers/SpeechRecognition/RNPermissionHandlerSpeechRecognition.m
  38. 5
    0
      ios/PermissionHandlers/StoreKit/RNPermissionHandlerStoreKit.h
  39. 37
    0
      ios/PermissionHandlers/StoreKit/RNPermissionHandlerStoreKit.m
  40. 0
    17
      ios/Permissions/RNPAudioVideo.h
  41. 0
    48
      ios/Permissions/RNPAudioVideo.m
  42. 0
    16
      ios/Permissions/RNPBackgroundRefresh.h
  43. 0
    28
      ios/Permissions/RNPBackgroundRefresh.m
  44. 0
    17
      ios/Permissions/RNPBluetooth.h
  45. 0
    66
      ios/Permissions/RNPBluetooth.m
  46. 0
    17
      ios/Permissions/RNPContacts.h
  47. 0
    69
      ios/Permissions/RNPContacts.m
  48. 0
    17
      ios/Permissions/RNPEvent.h
  49. 0
    48
      ios/Permissions/RNPEvent.m
  50. 0
    17
      ios/Permissions/RNPLocation.h
  51. 0
    78
      ios/Permissions/RNPLocation.m
  52. 0
    17
      ios/Permissions/RNPMediaLibrary.h
  53. 0
    41
      ios/Permissions/RNPMediaLibrary.m
  54. 0
    14
      ios/Permissions/RNPMotion.h
  55. 0
    62
      ios/Permissions/RNPMotion.m
  56. 0
    17
      ios/Permissions/RNPNotification.h
  57. 0
    70
      ios/Permissions/RNPNotification.m
  58. 0
    17
      ios/Permissions/RNPPhoto.h
  59. 0
    43
      ios/Permissions/RNPPhoto.m
  60. 0
    17
      ios/Permissions/RNPSpeechRecognition.h
  61. 0
    44
      ios/Permissions/RNPSpeechRecognition.m
  62. 0
    42
      ios/RCTConvert+RNPStatus.h
  63. 0
    29
      ios/RCTConvert+RNPStatus.m
  64. 57
    0
      ios/RCTConvert+RNPermission.h
  65. 58
    0
      ios/RCTConvert+RNPermission.m
  66. 90
    4
      ios/RNPermissions.podspec
  67. 310
    0
      ios/RNPermissions.xcodeproj/project.pbxproj
  68. 36
    0
      ios/RNPermissionsManager.h
  69. 258
    0
      ios/RNPermissionsManager.m
  70. 0
    19
      ios/ReactNativePermissions.h
  71. 0
    247
      ios/ReactNativePermissions.m
  72. 0
    348
      ios/ReactNativePermissions.xcodeproj/project.pbxproj
  73. 0
    113
      lib/permissions.android.js
  74. 0
    105
      lib/permissions.ios.js
  75. 9
    8
      package.json
  76. 4
    4
      yarn.lock

+ 59
- 3
.flowconfig 查看文件

@@ -1,14 +1,70 @@
1 1
 [ignore]
2
+; We fork some components by platform
3
+.*/*[.]android.js
4
+
5
+; Ignore "BUCK" generated dirs
6
+<PROJECT_ROOT>/\.buckd/
7
+
8
+; Ignore unexpected extra "@providesModule"
9
+.*/node_modules/.*/node_modules/fbjs/.*
10
+
11
+; Ignore duplicate module providers
12
+; For RN Apps installed via npm, "Libraries" folder is inside
13
+; "node_modules/react-native" but in the source repo it is in the root
14
+.*/Libraries/react-native/React.js
15
+
16
+; Ignore polyfills
17
+.*/Libraries/polyfills/.*
18
+
19
+; Ignore metro
20
+.*/node_modules/metro/.*
2 21
 
3 22
 [include]
4 23
 
5 24
 [libs]
6
-
7
-[lints]
25
+node_modules/react-native/Libraries/react-native/react-native-interface.js
26
+node_modules/react-native/flow/
27
+node_modules/react-native/flow-github/
8 28
 
9 29
 [options]
30
+emoji=true
31
+
32
+esproposal.optional_chaining=enable
33
+esproposal.nullish_coalescing=enable
34
+
35
+module.system=haste
36
+module.system.haste.use_name_reducers=true
37
+# get basename
38
+module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
39
+# strip .js or .js.flow suffix
40
+module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
41
+# strip .ios suffix
42
+module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
43
+module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
44
+module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
45
+module.system.haste.paths.blacklist=.*/__tests__/.*
46
+module.system.haste.paths.blacklist=.*/__mocks__/.*
47
+module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
48
+module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
49
+
10 50
 munge_underscores=true
51
+
52
+module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
53
+
54
+module.file_ext=.js
55
+module.file_ext=.jsx
56
+module.file_ext=.json
57
+module.file_ext=.native.js
58
+
59
+suppress_type=$FlowIssue
11 60
 suppress_type=$FlowFixMe
61
+suppress_type=$FlowFixMeProps
62
+suppress_type=$FlowFixMeState
63
+
64
+suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
65
+suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
66
+suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
67
+suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
12 68
 
13 69
 [version]
14
-^0.91.0
70
+^0.86.0

+ 54
- 9
.gitignore 查看文件

@@ -1,15 +1,60 @@
1
-*.xcworkspace
1
+# OSX
2
+#
3
+.DS_Store
4
+
5
+# Xcode
6
+#
7
+build/
8
+*.pbxuser
9
+!default.pbxuser
10
+*.mode1v3
11
+!default.mode1v3
12
+*.mode2v3
13
+!default.mode2v3
14
+*.perspectivev3
15
+!default.perspectivev3
2 16
 xcuserdata
17
+*.xccheckout
18
+*.moved-aside
19
+DerivedData
20
+*.hmap
21
+*.ipa
22
+*.xcuserstate
23
+project.xcworkspace
24
+
25
+# Android/IntelliJ
26
+#
27
+build/
28
+.idea
29
+.gradle
30
+local.properties
31
+*.iml
3 32
 
4
-npm-debug.log*
5
-yarn-debug.log*
6
-yarn-error.log*
33
+# node.js
34
+#
7 35
 node_modules/
36
+npm-debug.log
37
+yarn-error.log
8 38
 
9
-*.DS_Store
10
-Thumbs.db
11
-Desktop.ini
39
+# BUCK
40
+buck-out/
41
+\.buckd/
42
+*.keystore
12 43
 
13
-.vscode/
44
+# fastlane
45
+#
46
+# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47
+# screenshots whenever they are needed.
48
+# For more information about the recommended setup visit:
49
+# https://docs.fastlane.tools/best-practices/source-control/
14 50
 
15
-android/build/
51
+*/fastlane/report.xml
52
+*/fastlane/Preview.html
53
+*/fastlane/screenshots
54
+
55
+# Bundle artifact
56
+*.jsbundle
57
+
58
+# VScode
59
+#
60
+.vscode/

+ 25
- 0
android/build.gradle 查看文件

@@ -0,0 +1,25 @@
1
+apply plugin: 'com.android.library'
2
+
3
+def safeExtGet(prop, fallback) {
4
+  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
5
+}
6
+
7
+android {
8
+  compileSdkVersion safeExtGet('compileSdkVersion', 26)
9
+  buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
10
+
11
+  defaultConfig {
12
+    minSdkVersion safeExtGet('minSdkVersion', 16)
13
+    targetSdkVersion safeExtGet('targetSdkVersion', 26)
14
+    versionCode 1
15
+    versionName "1.0"
16
+  }
17
+
18
+  lintOptions {
19
+    abortOnError false
20
+  }
21
+}
22
+
23
+dependencies {
24
+  implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}" // From node_modules
25
+}

+ 4
- 0
android/src/main/AndroidManifest.xml 查看文件

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+    package="com.yonahforst.rnpermissions">
4
+</manifest>

+ 52
- 0
android/src/main/java/com/yonahforst/rnpermissions/RNPermissionsModule.java 查看文件

@@ -0,0 +1,52 @@
1
+package com.yonahforst.rnpermissions;
2
+
3
+import android.Manifest;
4
+import android.content.Intent;
5
+import android.net.Uri;
6
+import android.provider.Settings;
7
+
8
+import com.facebook.react.bridge.Promise;
9
+import com.facebook.react.bridge.ReactApplicationContext;
10
+import com.facebook.react.bridge.ReactContextBaseJavaModule;
11
+import com.facebook.react.bridge.ReactMethod;
12
+
13
+public class RNPermissionsModule extends ReactContextBaseJavaModule {
14
+
15
+  private static final String ERROR_INVALID_ACTIVITY = "E_INVALID_ACTIVITY";
16
+
17
+  public RNPermissionsModule(ReactApplicationContext reactContext) {
18
+    super(reactContext);
19
+  }
20
+
21
+  @Override
22
+  public String getName() {
23
+    return "RNPermissions";
24
+  }
25
+
26
+  @ReactMethod
27
+  public void isPermissionAvailable(final String permission, final Promise promise) {
28
+    String fieldName = permission.substring(permission.lastIndexOf('.') + 1);
29
+
30
+    try {
31
+      Manifest.permission.class.getField(fieldName);
32
+      promise.resolve(true);
33
+    } catch (NoSuchFieldException e) {
34
+      promise.resolve(false);
35
+    }
36
+  }
37
+
38
+  @ReactMethod
39
+  public void openSettings(final Promise promise) {
40
+    try {
41
+      String packageName = getReactApplicationContext().getPackageName();
42
+      Intent intent = new Intent();
43
+      intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
44
+      intent.setData(Uri.fromParts("package", packageName , null));
45
+      getReactApplicationContext().startActivity(intent);
46
+
47
+      promise.resolve(true);
48
+    } catch (Exception e) {
49
+      promise.reject(ERROR_INVALID_ACTIVITY, e);
50
+    }
51
+  }
52
+}

+ 23
- 0
android/src/main/java/com/yonahforst/rnpermissions/RNPermissionsPackage.java 查看文件

@@ -0,0 +1,23 @@
1
+package com.yonahforst.rnpermissions;
2
+
3
+import com.facebook.react.ReactPackage;
4
+import com.facebook.react.bridge.NativeModule;
5
+import com.facebook.react.bridge.ReactApplicationContext;
6
+import com.facebook.react.uimanager.ViewManager;
7
+
8
+import java.util.Arrays;
9
+import java.util.Collections;
10
+import java.util.List;
11
+
12
+public class RNPermissionsPackage implements ReactPackage {
13
+
14
+  @Override
15
+  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16
+    return Arrays.<NativeModule>asList(new RNPermissionsModule(reactContext));
17
+  }
18
+
19
+  @Override
20
+  public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
21
+    return Collections.emptyList();
22
+  }
23
+}

+ 2
- 2
index.js 查看文件

@@ -1,4 +1,4 @@
1 1
 // @flow
2 2
 
3
-import Permissions from "./lib/permissions";
4
-export default Permissions;
3
+// import Permissions from "./lib/permissions";
4
+export default 42;

+ 5
- 0
ios/PermissionHandlers/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerBluetoothPeripheral : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 66
- 0
ios/PermissionHandlers/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m 查看文件

@@ -0,0 +1,66 @@
1
+#import "RNPermissionHandlerBluetoothPeripheral.h"
2
+
3
+@import CoreBluetooth;
4
+
5
+@interface RNPermissionHandlerBluetoothPeripheral() <CBPeripheralManagerDelegate>
6
+
7
+@property (nonatomic) CBPeripheralManager* peripheralManager;
8
+@property (nonatomic, copy) void (^resolve)(RNPermissionStatus status);
9
+@property (nonatomic, copy) void (^reject)(NSError *error);
10
+
11
+@end
12
+
13
+@implementation RNPermissionHandlerBluetoothPeripheral
14
+
15
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
16
+  return [RNPermissionsManager hasBackgroundModeEnabled:@"bluetooth-peripheral"] ? @[@"NSBluetoothPeripheralUsageDescription"] : nil;
17
+}
18
+
19
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
20
+             withRejecter:(void (__unused ^)(NSError *error))reject {
21
+  switch ([CBPeripheralManager authorizationStatus]) {
22
+    case CBPeripheralManagerAuthorizationStatusNotDetermined:
23
+      return resolve(RNPermissionStatusNotDetermined);
24
+    case CBPeripheralManagerAuthorizationStatusRestricted:
25
+      return resolve(RNPermissionStatusRestricted);
26
+    case CBPeripheralManagerAuthorizationStatusDenied:
27
+      return resolve(RNPermissionStatusDenied);
28
+    case CBPeripheralManagerAuthorizationStatusAuthorized:
29
+      return resolve(RNPermissionStatusAuthorized);
30
+  }
31
+}
32
+
33
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
34
+              withResolver:(void (^)(RNPermissionStatus status))resolve
35
+              withRejecter:(void (^)(NSError *error))reject {
36
+  _resolve = resolve;
37
+  _reject = reject;
38
+  
39
+  _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:@{
40
+    CBPeripheralManagerOptionShowPowerAlertKey: @false,
41
+  }];
42
+  
43
+  [_peripheralManager startAdvertising:@{}];
44
+}
45
+
46
+- (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
47
+  CBManagerState state = peripheral.state;
48
+  
49
+  [_peripheralManager stopAdvertising];
50
+  _peripheralManager = nil;
51
+  
52
+  switch (state) {
53
+    case CBManagerStatePoweredOn:
54
+      return [self checkWithResolver:_resolve withRejecter:_reject];
55
+    case CBManagerStatePoweredOff:
56
+    case CBManagerStateResetting:
57
+    case CBManagerStateUnsupported:
58
+      return _resolve(RNPermissionStatusNotAvailable);
59
+    case CBManagerStateUnknown:
60
+      return _resolve(RNPermissionStatusNotDetermined);
61
+    case CBManagerStateUnauthorized:
62
+      return _resolve(RNPermissionStatusDenied);
63
+  }
64
+}
65
+
66
+@end

+ 5
- 0
ios/PermissionHandlers/Calendars/RNPermissionHandlerCalendars.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerCalendars : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 37
- 0
ios/PermissionHandlers/Calendars/RNPermissionHandlerCalendars.m 查看文件

@@ -0,0 +1,37 @@
1
+#import "RNPermissionHandlerCalendars.h"
2
+
3
+@import EventKit;
4
+
5
+@implementation RNPermissionHandlerCalendars
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSCalendarsUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent]) {
14
+    case EKAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case EKAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case EKAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case EKAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [[EKEventStore new] requestAccessToEntityType:EKEntityTypeEvent completion:^(__unused BOOL granted, NSError * _Nullable error) {
29
+    if (error != nil) {
30
+      reject(error);
31
+    } else {
32
+      [self checkWithResolver:resolve withRejecter:reject];
33
+    }
34
+  }];
35
+}
36
+
37
+@end

+ 5
- 0
ios/PermissionHandlers/Camera/RNPermissionHandlerCamera.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerCamera : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 33
- 0
ios/PermissionHandlers/Camera/RNPermissionHandlerCamera.m 查看文件

@@ -0,0 +1,33 @@
1
+#import "RNPermissionHandlerCamera.h"
2
+
3
+@import AVFoundation;
4
+
5
+@implementation RNPermissionHandlerCamera
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSCameraUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) {
14
+    case AVAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case AVAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case AVAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case AVAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+  
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(__unused BOOL granted) {
29
+    [self checkWithResolver:resolve withRejecter:reject];
30
+  }];
31
+}
32
+
33
+@end

+ 5
- 0
ios/PermissionHandlers/Contacts/RNPermissionHandlerContacts.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerContacts : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 37
- 0
ios/PermissionHandlers/Contacts/RNPermissionHandlerContacts.m 查看文件

@@ -0,0 +1,37 @@
1
+#import "RNPermissionHandlerContacts.h"
2
+
3
+@import Contacts;
4
+
5
+@implementation RNPermissionHandlerContacts
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSContactsUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]) {
14
+    case CNAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case CNAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case CNAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case CNAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [[CNContactStore new] requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(__unused BOOL granted, NSError * _Nullable error) {
29
+    if (error != nil && error.code != 100) {
30
+      reject(error);
31
+    } else {
32
+      [self checkWithResolver:resolve withRejecter:reject];
33
+    }
34
+  }];
35
+}
36
+
37
+@end

+ 5
- 0
ios/PermissionHandlers/FaceID/RNPermissionHandlerFaceID.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerFaceID : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 75
- 0
ios/PermissionHandlers/FaceID/RNPermissionHandlerFaceID.m 查看文件

@@ -0,0 +1,75 @@
1
+#import "RNPermissionHandlerFaceID.h"
2
+
3
+@import LocalAuthentication;
4
+
5
+@implementation RNPermissionHandlerFaceID
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSFaceIDUsageDescription"];
9
+}
10
+
11
+- (void)handleError:(NSError *)error
12
+       withResolver:(void (^)(RNPermissionStatus status))resolve
13
+       withRejecter:(void (^)(NSError *error))reject {
14
+  if (error.code == -6) {
15
+    resolve(RNPermissionStatusDenied);
16
+  } else {
17
+    reject(error);
18
+  }
19
+}
20
+
21
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
22
+             withRejecter:(void (^)(NSError *error))reject {
23
+  if (@available(iOS 11.0, *)) {
24
+    if (![RNPermissionsManager hasBeenRequestedOnce:self]) {
25
+      return resolve(RNPermissionStatusNotDetermined);
26
+    }
27
+
28
+    LAContext *context = [LAContext new];
29
+    NSError *error;
30
+    [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
31
+
32
+    if (error != nil) {
33
+      return [self handleError:error withResolver:resolve withRejecter:reject];
34
+    }
35
+    if (context.biometryType != LABiometryTypeFaceID) {
36
+      return resolve(RNPermissionStatusNotAvailable);
37
+    }
38
+
39
+    resolve(RNPermissionStatusAuthorized);
40
+  } else {
41
+    resolve(RNPermissionStatusNotAvailable);
42
+  }
43
+}
44
+
45
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
46
+              withResolver:(void (^)(RNPermissionStatus status))resolve
47
+              withRejecter:(void (^)(NSError *error))reject {
48
+  if (@available(iOS 11.0, *)) {
49
+    LAContext *context = [LAContext new];
50
+    NSError *error;
51
+    [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error];
52
+
53
+    if (error != nil) {
54
+      return [self handleError:error withResolver:resolve withRejecter:reject];
55
+    }
56
+    if (context.biometryType != LABiometryTypeFaceID) {
57
+      return resolve(RNPermissionStatusNotAvailable);
58
+    }
59
+    if ([RNPermissionsManager hasBeenRequestedOnce:self]) {
60
+      return resolve(RNPermissionStatusAuthorized);
61
+    }
62
+
63
+    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSFaceIDUsageDescription"] reply:^(BOOL success, NSError * _Nullable evaluationError) {
64
+      if (evaluationError != nil) {
65
+        [self handleError:evaluationError withResolver:resolve withRejecter:reject];
66
+      } else {
67
+        resolve(success ? RNPermissionStatusAuthorized : RNPermissionStatusDenied);
68
+      }
69
+    }];
70
+  } else {
71
+    resolve(RNPermissionStatusNotAvailable);
72
+  }
73
+}
74
+
75
+@end

+ 5
- 0
ios/PermissionHandlers/LocationAlways/RNPermissionHandlerLocationAlways.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerLocationAlways : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 88
- 0
ios/PermissionHandlers/LocationAlways/RNPermissionHandlerLocationAlways.m 查看文件

@@ -0,0 +1,88 @@
1
+#import "RNPermissionHandlerLocationAlways.h"
2
+
3
+@import CoreLocation;
4
+@import UIKit;
5
+
6
+@interface RNPermissionHandlerLocationAlways() <CLLocationManagerDelegate>
7
+
8
+@property (nonatomic) CLLocationManager *locationManager;
9
+@property (nonatomic) bool initialChangeEventFired;
10
+@property (nonatomic, copy) void (^resolve)(RNPermissionStatus status);
11
+@property (nonatomic, copy) void (^reject)(NSError *error);
12
+
13
+@end
14
+
15
+@implementation RNPermissionHandlerLocationAlways
16
+
17
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
18
+  return @[
19
+    @"NSLocationAlwaysAndWhenInUseUsageDescription",
20
+    @"NSLocationAlwaysUsageDescription",
21
+  ];
22
+}
23
+
24
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
25
+             withRejecter:(void (__unused ^)(NSError *error))reject {
26
+  if (![CLLocationManager locationServicesEnabled]) {
27
+    return resolve(RNPermissionStatusNotAvailable);
28
+  }
29
+  
30
+  switch ([CLLocationManager authorizationStatus]) {
31
+    case kCLAuthorizationStatusNotDetermined:
32
+      return resolve(RNPermissionStatusNotDetermined);
33
+    case kCLAuthorizationStatusRestricted:
34
+      return resolve(RNPermissionStatusRestricted);
35
+    case kCLAuthorizationStatusAuthorizedWhenInUse:
36
+    case kCLAuthorizationStatusDenied:
37
+      return resolve(RNPermissionStatusDenied);
38
+    case kCLAuthorizationStatusAuthorizedAlways:
39
+      return resolve(RNPermissionStatusAuthorized);
40
+  }
41
+}
42
+
43
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
44
+              withResolver:(void (^)(RNPermissionStatus status))resolve
45
+              withRejecter:(void (^)(NSError *error))reject {
46
+  CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
47
+  
48
+  if ((status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) ||
49
+      ([RNPermissionsManager hasBeenRequestedOnce:self] && status == kCLAuthorizationStatusAuthorizedWhenInUse)) {
50
+    return [self checkWithResolver:resolve withRejecter:reject];
51
+  }
52
+  
53
+  _resolve = resolve;
54
+  _reject = reject;
55
+  
56
+  if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
57
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UIApplicationDidBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
58
+  }
59
+  
60
+  _locationManager = [CLLocationManager new];
61
+  [_locationManager setDelegate:self];
62
+  [_locationManager requestAlwaysAuthorization];
63
+}
64
+
65
+- (void)onAuthorizationStatus {
66
+  [self checkWithResolver:_resolve withRejecter:_reject];
67
+  
68
+  [_locationManager setDelegate:nil];
69
+  _locationManager = nil;
70
+}
71
+
72
+- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
73
+  if (!_initialChangeEventFired) {
74
+    _initialChangeEventFired = true;
75
+  } else {
76
+    [self onAuthorizationStatus];
77
+  }
78
+}
79
+
80
+- (void)UIApplicationDidBecomeActiveNotification:(NSNotification *)notification {
81
+  if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse) {
82
+    [self onAuthorizationStatus];
83
+  }
84
+  
85
+  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
86
+}
87
+
88
+@end

+ 5
- 0
ios/PermissionHandlers/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerLocationWhenInUse : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 65
- 0
ios/PermissionHandlers/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.m 查看文件

@@ -0,0 +1,65 @@
1
+#import "RNPermissionHandlerLocationWhenInUse.h"
2
+
3
+@import CoreLocation;
4
+
5
+@interface RNPermissionHandlerLocationWhenInUse() <CLLocationManagerDelegate>
6
+
7
+@property (nonatomic) CLLocationManager *locationManager;
8
+@property (nonatomic) bool initialChangeEventFired;
9
+@property (nonatomic, copy) void (^resolve)(RNPermissionStatus status);
10
+@property (nonatomic, copy) void (^reject)(NSError *error);
11
+
12
+@end
13
+
14
+@implementation RNPermissionHandlerLocationWhenInUse
15
+
16
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
17
+  return @[@"NSLocationWhenInUseUsageDescription"];
18
+}
19
+
20
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
21
+             withRejecter:(void (__unused ^)(NSError *error))reject {
22
+  if (![CLLocationManager locationServicesEnabled]) {
23
+    return resolve(RNPermissionStatusNotAvailable);
24
+  }
25
+  
26
+  switch ([CLLocationManager authorizationStatus]) {
27
+    case kCLAuthorizationStatusNotDetermined:
28
+      return resolve(RNPermissionStatusNotDetermined);
29
+    case kCLAuthorizationStatusRestricted:
30
+      return resolve(RNPermissionStatusRestricted);
31
+    case kCLAuthorizationStatusDenied:
32
+      return resolve(RNPermissionStatusDenied);
33
+    case kCLAuthorizationStatusAuthorizedWhenInUse:
34
+    case kCLAuthorizationStatusAuthorizedAlways:
35
+      return resolve(RNPermissionStatusAuthorized);
36
+  }
37
+}
38
+
39
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
40
+              withResolver:(void (^)(RNPermissionStatus status))resolve
41
+              withRejecter:(void (^)(NSError *error))reject {
42
+  if ([CLLocationManager locationServicesEnabled] != kCLAuthorizationStatusNotDetermined) {
43
+    return [self checkWithResolver:resolve withRejecter:reject];
44
+  }
45
+  
46
+  _resolve = resolve;
47
+  _reject = reject;
48
+  
49
+  _locationManager = [CLLocationManager new];
50
+  [_locationManager setDelegate:self];
51
+  [_locationManager requestWhenInUseAuthorization];
52
+}
53
+
54
+- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
55
+  if (!_initialChangeEventFired) {
56
+    _initialChangeEventFired = true;
57
+  } else {
58
+    [self checkWithResolver:_resolve withRejecter:_reject];
59
+    
60
+    [_locationManager setDelegate:nil];
61
+    _locationManager = nil;
62
+  }
63
+}
64
+
65
+@end

+ 5
- 0
ios/PermissionHandlers/MediaLibrary/RNPermissionHandlerMediaLibrary.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerMediaLibrary : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 41
- 0
ios/PermissionHandlers/MediaLibrary/RNPermissionHandlerMediaLibrary.m 查看文件

@@ -0,0 +1,41 @@
1
+#import "RNPermissionHandlerMediaLibrary.h"
2
+
3
+@import MediaPlayer;
4
+
5
+@implementation RNPermissionHandlerMediaLibrary
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSAppleMusicUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  if (@available(iOS 9.3, *)) {
14
+    switch ([MPMediaLibrary authorizationStatus]) {
15
+      case MPMediaLibraryAuthorizationStatusNotDetermined:
16
+        return resolve(RNPermissionStatusNotDetermined);
17
+      case MPMediaLibraryAuthorizationStatusRestricted:
18
+        return resolve(RNPermissionStatusRestricted);
19
+      case MPMediaLibraryAuthorizationStatusDenied:
20
+        return resolve(RNPermissionStatusDenied);
21
+      case MPMediaLibraryAuthorizationStatusAuthorized:
22
+        return resolve(RNPermissionStatusAuthorized);
23
+    }
24
+  } else {
25
+    resolve(RNPermissionStatusAuthorized);
26
+  }
27
+}
28
+
29
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
30
+              withResolver:(void (^)(RNPermissionStatus status))resolve
31
+              withRejecter:(void (^)(NSError *error))reject {
32
+  if (@available(iOS 9.3, *)) {
33
+    [MPMediaLibrary requestAuthorization:^(__unused MPMediaLibraryAuthorizationStatus status) {
34
+      [self checkWithResolver:resolve withRejecter:reject];
35
+    }];
36
+  } else {
37
+    resolve(RNPermissionStatusAuthorized);
38
+  }
39
+}
40
+
41
+@end

+ 5
- 0
ios/PermissionHandlers/Microphone/RNPermissionHandlerMicrophone.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerMicrophone : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 33
- 0
ios/PermissionHandlers/Microphone/RNPermissionHandlerMicrophone.m 查看文件

@@ -0,0 +1,33 @@
1
+#import "RNPermissionHandlerMicrophone.h"
2
+
3
+@import AVFoundation;
4
+
5
+@implementation RNPermissionHandlerMicrophone
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSMicrophoneUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
14
+    case AVAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case AVAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case AVAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case AVAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(__unused BOOL granted) {
29
+    [self checkWithResolver:resolve withRejecter:reject];
30
+  }];
31
+}
32
+
33
+@end

+ 5
- 0
ios/PermissionHandlers/Motion/RNPermissionHandlerMotion.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerMotion : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 74
- 0
ios/PermissionHandlers/Motion/RNPermissionHandlerMotion.m 查看文件

@@ -0,0 +1,74 @@
1
+#import "RNPermissionHandlerMotion.h"
2
+
3
+@import CoreMotion;
4
+
5
+static NSString* handlerKey = @"motion";
6
+
7
+@interface RNPermissionHandlerMotion()
8
+
9
+@property (nonatomic, strong) CMMotionActivityManager *motionActivityManager;
10
+@property (nonatomic, strong) NSOperationQueue *motionActivityQueue;
11
+
12
+@end
13
+
14
+@implementation RNPermissionHandlerMotion
15
+
16
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
17
+  return @[@"NSMotionUsageDescription"];
18
+}
19
+
20
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
21
+             withRejecter:(void (^)(NSError *error))reject {
22
+  if (![CMMotionActivityManager isActivityAvailable]) {
23
+    return resolve(RNPermissionStatusNotAvailable);
24
+  }
25
+  
26
+  if (@available(iOS 11.0, *)) {
27
+    switch ([CMMotionActivityManager authorizationStatus]) {
28
+      case CMAuthorizationStatusNotDetermined:
29
+        return resolve(RNPermissionStatusNotDetermined);
30
+      case CMAuthorizationStatusRestricted:
31
+        return resolve(RNPermissionStatusRestricted);
32
+      case CMAuthorizationStatusDenied:
33
+        return resolve(RNPermissionStatusDenied);
34
+      case CMAuthorizationStatusAuthorized:
35
+        return resolve(RNPermissionStatusAuthorized);
36
+    }
37
+  }
38
+  
39
+  if (![RNPermissionsManager hasBeenRequestedOnce:self]) {
40
+    return resolve(RNPermissionStatusNotDetermined);
41
+  }
42
+  
43
+  [self requestWithOptions:nil withResolver:resolve withRejecter:reject];
44
+}
45
+
46
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
47
+              withResolver:(void (^)(RNPermissionStatus status))resolve
48
+              withRejecter:(void (^)(NSError *error))reject {
49
+  if (![CMMotionActivityManager isActivityAvailable]) {
50
+    return resolve(RNPermissionStatusNotAvailable);
51
+  }
52
+  
53
+  _motionActivityManager = [CMMotionActivityManager new];
54
+  _motionActivityQueue = [NSOperationQueue new];
55
+  
56
+  [_motionActivityManager queryActivityStartingFromDate:[NSDate distantPast] toDate:[NSDate date] toQueue:_motionActivityQueue withHandler:^(NSArray<CMMotionActivity *> * _Nullable activities, NSError * _Nullable error) {
57
+    if (error != nil) {
58
+      if (error.code == CMErrorNotAuthorized || error.code == CMErrorMotionActivityNotAuthorized) {
59
+        resolve(RNPermissionStatusDenied);
60
+      } else {
61
+        reject(error);
62
+      }
63
+    } else if (activities) {
64
+      resolve(RNPermissionStatusAuthorized);
65
+    } else {
66
+      resolve(RNPermissionStatusNotDetermined);
67
+    }
68
+    
69
+    self->_motionActivityManager = nil;
70
+    self->_motionActivityQueue = nil;
71
+  }];
72
+}
73
+
74
+@end

+ 5
- 0
ios/PermissionHandlers/Notifications/RNPermissionHandlerNotifications.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerNotifications : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 98
- 0
ios/PermissionHandlers/Notifications/RNPermissionHandlerNotifications.m 查看文件

@@ -0,0 +1,98 @@
1
+#import "RNPermissionHandlerNotifications.h"
2
+
3
+@import UserNotifications;
4
+@import UIKit;
5
+
6
+@implementation RNPermissionHandlerNotifications
7
+
8
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
9
+             withRejecter:(void (__unused ^)(NSError *error))reject {
10
+  if (@available(iOS 10.0, *)) {
11
+    [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
12
+      switch (settings.authorizationStatus) {
13
+        case UNAuthorizationStatusNotDetermined:
14
+          return resolve(RNPermissionStatusNotDetermined);
15
+        case UNAuthorizationStatusDenied:
16
+          return resolve(RNPermissionStatusDenied);
17
+#ifdef __IPHONE_12_0
18
+        case UNAuthorizationStatusProvisional:
19
+#endif
20
+        case UNAuthorizationStatusAuthorized:
21
+          return resolve(RNPermissionStatusAuthorized);
22
+      }
23
+    }];
24
+  } else {
25
+    UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
26
+    
27
+    if (settings == nil || settings.types == UIUserNotificationTypeNone) {
28
+      resolve(RNPermissionStatusNotDetermined);
29
+    } else {
30
+      resolve(RNPermissionStatusAuthorized);
31
+    }
32
+  }
33
+}
34
+
35
+- (void)requestWithOptions:(NSDictionary * _Nullable)options
36
+              withResolver:(void (^)(RNPermissionStatus status))resolve
37
+              withRejecter:(void (^)(NSError *error))reject {
38
+  if (@available(iOS 10.0, *)) {
39
+    UNAuthorizationOptions toRequest = UNAuthorizationOptionNone;
40
+
41
+    if (options != nil) {
42
+      NSArray<NSString *> *notificationOptions = [options objectForKey:@"notificationOptions"];
43
+      
44
+      if (notificationOptions != nil && [notificationOptions isKindOfClass:[NSArray class]]) {
45
+#if RCT_DEV
46
+        // @TODO check if it's possible to use RCTConvert + RCT_ENUM_CONVERTER
47
+        // https://developer.apple.com/documentation/usernotifications/unnotificationsettings?language=objc
48
+        
49
+        NSArray<NSString *> *possible = [[NSArray alloc] initWithObjects:@"badge", @"sound", @"alert", @"carPlay", @"provisional", @"criticalAlert", nil];
50
+        
51
+        for (NSString *option in notificationOptions) {
52
+          if (![possible containsObject:option]) {
53
+            return [RNPermissionsManager logErrorMessage:[NSString stringWithFormat:@"Invalid notificationOptions value : %@. Must be one of : %@.", option, [possible componentsJoinedByString:@", "]]];
54
+          }
55
+        }
56
+#endif
57
+        
58
+        if ([notificationOptions containsObject:@"badge"]) {
59
+          toRequest += UNAuthorizationOptionBadge;
60
+        }
61
+        if ([notificationOptions containsObject:@"sound"]) {
62
+          toRequest += UNAuthorizationOptionSound;
63
+        }
64
+        if ([notificationOptions containsObject:@"alert"]) {
65
+          toRequest += UNAuthorizationOptionAlert;
66
+        }
67
+        if ([notificationOptions containsObject:@"carPlay"]) {
68
+          toRequest += UNAuthorizationOptionCarPlay;
69
+        }
70
+        
71
+        if (@available(iOS 12.0, *)) {
72
+          if ([notificationOptions containsObject:@"provisional"]) {
73
+            toRequest += UNAuthorizationOptionProvisional;
74
+          }
75
+          if ([notificationOptions containsObject:@"criticalAlert"]) {
76
+            toRequest += UNAuthorizationOptionCriticalAlert;
77
+          }
78
+        }
79
+      } else {
80
+        toRequest += UNAuthorizationOptionBadge;
81
+        toRequest += UNAuthorizationOptionSound;
82
+        toRequest += UNAuthorizationOptionAlert;
83
+      }
84
+    }
85
+    
86
+    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:toRequest completionHandler:^(BOOL granted, NSError * _Nullable error) {
87
+      if (error != nil) {
88
+        reject(error);
89
+      } else {
90
+        [self checkWithResolver:resolve withRejecter:reject];
91
+      }
92
+    }];
93
+  } else {
94
+    [self checkWithResolver:resolve withRejecter:reject];
95
+  }
96
+}
97
+
98
+@end

+ 5
- 0
ios/PermissionHandlers/PhotoLibrary/RNPermissionHandlerPhotoLibrary.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerPhotoLibrary : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 33
- 0
ios/PermissionHandlers/PhotoLibrary/RNPermissionHandlerPhotoLibrary.m 查看文件

@@ -0,0 +1,33 @@
1
+#import "RNPermissionHandlerPhotoLibrary.h"
2
+
3
+@import Photos;
4
+
5
+@implementation RNPermissionHandlerPhotoLibrary
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSPhotoLibraryUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([PHPhotoLibrary authorizationStatus]) {
14
+    case PHAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case PHAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case PHAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case PHAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [PHPhotoLibrary requestAuthorization:^(__unused PHAuthorizationStatus status) {
29
+    [self checkWithResolver:resolve withRejecter:reject];
30
+  }];
31
+}
32
+
33
+@end

+ 5
- 0
ios/PermissionHandlers/Reminders/RNPermissionHandlerReminders.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerReminders : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 37
- 0
ios/PermissionHandlers/Reminders/RNPermissionHandlerReminders.m 查看文件

@@ -0,0 +1,37 @@
1
+#import "RNPermissionHandlerReminders.h"
2
+
3
+@import EventKit;
4
+
5
+@implementation RNPermissionHandlerReminders
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSRemindersUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  switch ([EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]) {
14
+    case EKAuthorizationStatusNotDetermined:
15
+      return resolve(RNPermissionStatusNotDetermined);
16
+    case EKAuthorizationStatusRestricted:
17
+      return resolve(RNPermissionStatusRestricted);
18
+    case EKAuthorizationStatusDenied:
19
+      return resolve(RNPermissionStatusDenied);
20
+    case EKAuthorizationStatusAuthorized:
21
+      return resolve(RNPermissionStatusAuthorized);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  [[EKEventStore new] requestAccessToEntityType:EKEntityTypeReminder completion:^(__unused BOOL granted, NSError * _Nullable error) {
29
+    if (error != nil) {
30
+      reject(error);
31
+    } else {
32
+      [self checkWithResolver:resolve withRejecter:reject];
33
+    }
34
+  }];
35
+}
36
+
37
+@end

+ 5
- 0
ios/PermissionHandlers/Siri/RNPermissionHandlerSiri.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerSiri : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 41
- 0
ios/PermissionHandlers/Siri/RNPermissionHandlerSiri.m 查看文件

@@ -0,0 +1,41 @@
1
+#import "RNPermissionHandlerSiri.h"
2
+
3
+@import Intents;
4
+
5
+@implementation RNPermissionHandlerSiri
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSSiriUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  if (@available(iOS 10.0, *)) {
14
+    switch ([INPreferences siriAuthorizationStatus]) {
15
+      case INSiriAuthorizationStatusNotDetermined:
16
+        return resolve(RNPermissionStatusNotDetermined);
17
+      case INSiriAuthorizationStatusRestricted:
18
+        return resolve(RNPermissionStatusRestricted);
19
+      case INSiriAuthorizationStatusDenied:
20
+        return resolve(RNPermissionStatusDenied);
21
+      case INSiriAuthorizationStatusAuthorized:
22
+        return resolve(RNPermissionStatusAuthorized);
23
+    }
24
+  } else {
25
+    resolve(RNPermissionStatusNotAvailable);
26
+  }
27
+}
28
+
29
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
30
+              withResolver:(void (^)(RNPermissionStatus status))resolve
31
+              withRejecter:(void (^)(NSError *error))reject {
32
+  if (@available(iOS 10.0, *)) {
33
+    [INPreferences requestSiriAuthorization:^(__unused INSiriAuthorizationStatus status) {
34
+      [self checkWithResolver:resolve withRejecter:reject];
35
+    }];
36
+  } else {
37
+    resolve(RNPermissionStatusNotAvailable);
38
+  }
39
+}
40
+
41
+@end

+ 5
- 0
ios/PermissionHandlers/SpeechRecognition/RNPermissionHandlerSpeechRecognition.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerSpeechRecognition : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 41
- 0
ios/PermissionHandlers/SpeechRecognition/RNPermissionHandlerSpeechRecognition.m 查看文件

@@ -0,0 +1,41 @@
1
+#import "RNPermissionHandlerSpeechRecognition.h"
2
+
3
+@import Speech;
4
+
5
+@implementation RNPermissionHandlerSpeechRecognition
6
+
7
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
8
+  return @[@"NSSpeechRecognitionUsageDescription"];
9
+}
10
+
11
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
12
+             withRejecter:(void (__unused ^)(NSError *error))reject {
13
+  if (@available(iOS 10.0, *)) {
14
+    switch ([SFSpeechRecognizer authorizationStatus]) {
15
+      case SFSpeechRecognizerAuthorizationStatusNotDetermined:
16
+        return resolve(RNPermissionStatusNotDetermined);
17
+      case SFSpeechRecognizerAuthorizationStatusRestricted:
18
+        return resolve(RNPermissionStatusRestricted);
19
+      case SFSpeechRecognizerAuthorizationStatusDenied:
20
+        return resolve(RNPermissionStatusDenied);
21
+      case SFSpeechRecognizerAuthorizationStatusAuthorized:
22
+        return resolve(RNPermissionStatusAuthorized);
23
+    }
24
+  } else {
25
+    resolve(RNPermissionStatusNotAvailable);
26
+  }
27
+}
28
+
29
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
30
+              withResolver:(void (^)(RNPermissionStatus status))resolve
31
+              withRejecter:(void (^)(NSError *error))reject {
32
+  if (@available(iOS 10.0, *)) {
33
+    [SFSpeechRecognizer requestAuthorization:^(__unused SFSpeechRecognizerAuthorizationStatus status) {
34
+      [self checkWithResolver:resolve withRejecter:reject];
35
+    }];
36
+  } else {
37
+    resolve(RNPermissionStatusNotAvailable);
38
+  }
39
+}
40
+
41
+@end

+ 5
- 0
ios/PermissionHandlers/StoreKit/RNPermissionHandlerStoreKit.h 查看文件

@@ -0,0 +1,5 @@
1
+#import "RNPermissionsManager.h"
2
+
3
+@interface RNPermissionHandlerStoreKit : NSObject<RNPermissionHandler>
4
+
5
+@end

+ 37
- 0
ios/PermissionHandlers/StoreKit/RNPermissionHandlerStoreKit.m 查看文件

@@ -0,0 +1,37 @@
1
+#import "RNPermissionHandlerStoreKit.h"
2
+
3
+@import StoreKit;
4
+
5
+@implementation RNPermissionHandlerStoreKit
6
+
7
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
8
+             withRejecter:(void (__unused ^)(NSError *error))reject {
9
+  if (@available(iOS 9.3, *)) {
10
+    switch ([SKCloudServiceController authorizationStatus]) {
11
+      case SKCloudServiceAuthorizationStatusNotDetermined:
12
+        return resolve(RNPermissionStatusNotDetermined);
13
+      case SKCloudServiceAuthorizationStatusRestricted:
14
+        return resolve(RNPermissionStatusRestricted);
15
+      case SKCloudServiceAuthorizationStatusDenied:
16
+        return resolve(RNPermissionStatusDenied);
17
+      case SKCloudServiceAuthorizationStatusAuthorized:
18
+        return resolve(RNPermissionStatusAuthorized);
19
+    }
20
+  } else {
21
+    resolve(RNPermissionStatusNotAvailable);
22
+  }
23
+}
24
+
25
+- (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
26
+              withResolver:(void (^)(RNPermissionStatus status))resolve
27
+              withRejecter:(void (^)(NSError *error))reject {
28
+  if (@available(iOS 9.3, *)) {
29
+    [SKCloudServiceController requestAuthorization:^(__unused SKCloudServiceAuthorizationStatus status) {
30
+      [self checkWithResolver:resolve withRejecter:reject];
31
+    }];
32
+  } else {
33
+    resolve(RNPermissionStatusNotAvailable);
34
+  }
35
+}
36
+
37
+@end

+ 0
- 17
ios/Permissions/RNPAudioVideo.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPAudioVideo.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPAudioVideo : NSObject
13
-
14
-+ (NSString *)getStatus:(NSString *)type;
15
-+ (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 48
ios/Permissions/RNPAudioVideo.m 查看文件

@@ -1,48 +0,0 @@
1
-//
2
-//  RNPCamera.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPAudioVideo.h"
10
-
11
-#import <AVFoundation/AVFoundation.h>
12
-
13
-@implementation RNPAudioVideo
14
-
15
-+ (NSString *)getStatus:(NSString *)type
16
-{
17
-    int status = [AVCaptureDevice authorizationStatusForMediaType:[self typeFromString:type]];
18
-    switch (status) {
19
-        case AVAuthorizationStatusAuthorized:
20
-            return RNPStatusAuthorized;
21
-        case AVAuthorizationStatusDenied:
22
-            return RNPStatusDenied;
23
-        case AVAuthorizationStatusRestricted:
24
-            return RNPStatusRestricted;
25
-        default:
26
-            return RNPStatusUndetermined;
27
-    }
28
-}
29
-
30
-+ (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler
31
-{
32
-    [AVCaptureDevice requestAccessForMediaType:[self typeFromString:type]
33
-                             completionHandler:^(BOOL granted) {
34
-                                 dispatch_async(dispatch_get_main_queue(), ^{
35
-                                     completionHandler([RNPAudioVideo getStatus:type]);
36
-                                 });
37
-                             }];
38
-}
39
-
40
-+ (NSString *)typeFromString:(NSString *)string {
41
-    if ([string isEqualToString:@"audio"]) {
42
-        return AVMediaTypeAudio;
43
-    } else {
44
-        return AVMediaTypeVideo;
45
-    }
46
-}
47
-
48
-@end

+ 0
- 16
ios/Permissions/RNPBackgroundRefresh.h 查看文件

@@ -1,16 +0,0 @@
1
-//
2
-//  RNPBackgroundRefresh.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPBackgroundRefresh : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-
16
-@end

+ 0
- 28
ios/Permissions/RNPBackgroundRefresh.m 查看文件

@@ -1,28 +0,0 @@
1
-//
2
-//  RNPBackgroundRefresh.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPBackgroundRefresh.h"
10
-
11
-@implementation RNPBackgroundRefresh
12
-
13
-+(NSString *)getStatus
14
-{
15
-    int status = [[UIApplication sharedApplication] backgroundRefreshStatus];
16
-    switch (status) {
17
-        case UIBackgroundRefreshStatusAvailable:
18
-            return RNPStatusAuthorized;
19
-        case UIBackgroundRefreshStatusDenied:
20
-            return RNPStatusDenied;
21
-        case UIBackgroundRefreshStatusRestricted:
22
-            return RNPStatusRestricted;
23
-        default:
24
-            return RNPStatusUndetermined;
25
-    }
26
-
27
-}
28
-@end

+ 0
- 17
ios/Permissions/RNPBluetooth.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPBluetooth.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPBluetooth : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-- (void)request:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 66
ios/Permissions/RNPBluetooth.m 查看文件

@@ -1,66 +0,0 @@
1
-//
2
-//  RNPBluetooth.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPBluetooth.h"
10
-#import <CoreBluetooth/CoreBluetooth.h>
11
-
12
-@interface RNPBluetooth() <CBPeripheralDelegate>
13
-@property (strong, nonatomic) CBPeripheralManager* peripheralManager;
14
-@property (copy) void (^completionHandler)(NSString *);
15
-@end
16
-
17
-@implementation RNPBluetooth
18
-
19
-+ (NSString *)getStatus
20
-{
21
-    int status = [CBPeripheralManager authorizationStatus];
22
-    switch (status) {
23
-        case CBPeripheralManagerAuthorizationStatusAuthorized:
24
-            return RNPStatusAuthorized;
25
-        case CBPeripheralManagerAuthorizationStatusDenied:
26
-            return RNPStatusDenied;
27
-        case CBPeripheralManagerAuthorizationStatusRestricted:
28
-            return RNPStatusRestricted;
29
-        default:
30
-            return RNPStatusUndetermined;
31
-    }
32
-}
33
-
34
-- (void)request:(void (^)(NSString *))completionHandler
35
-{
36
-    NSString *status = [RNPBluetooth getStatus];
37
-    
38
-    if (status == RNPStatusUndetermined) {
39
-        self.completionHandler = completionHandler;
40
-        
41
-        self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
42
-        [self.peripheralManager startAdvertising:@{}];
43
-    } else {
44
-        completionHandler(status);
45
-    }
46
-}
47
-
48
-- (void) peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheralManager
49
-{
50
-    if (self.peripheralManager) {
51
-        [self.peripheralManager stopAdvertising];
52
-        self.peripheralManager.delegate = nil;
53
-        self.peripheralManager = nil;
54
-    }
55
-    
56
-    if (self.completionHandler) {
57
-        //for some reason, checking permission right away returns denied. need to wait a tiny bit
58
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
59
-            self.completionHandler([self.class getStatus]);
60
-            self.completionHandler = nil;
61
-        });
62
-    }
63
-    
64
-}
65
-
66
-@end

+ 0
- 17
ios/Permissions/RNPContacts.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPContacts.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPContacts : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-+ (void)request:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 69
ios/Permissions/RNPContacts.m 查看文件

@@ -1,69 +0,0 @@
1
-//
2
-//  RNPContacts.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPContacts.h"
10
-#import <AddressBook/AddressBook.h>
11
-
12
-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
13
-@import Contacts;
14
-#endif
15
-
16
-@implementation RNPContacts
17
-
18
-+ (NSString *)getStatus
19
-{
20
-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
21
-    int status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
22
-    switch (status) {
23
-        case CNAuthorizationStatusAuthorized:
24
-            return RNPStatusAuthorized;
25
-        case CNAuthorizationStatusDenied:
26
-            return RNPStatusDenied;
27
-        case CNAuthorizationStatusRestricted:
28
-            return RNPStatusRestricted;
29
-        default:
30
-            return RNPStatusUndetermined;
31
-    }
32
-#else
33
-    int status = ABAddressBookGetAuthorizationStatus();
34
-    switch (status) {
35
-        case kABAuthorizationStatusAuthorized:
36
-            return RNPStatusAuthorized;
37
-        case kABAuthorizationStatusDenied:
38
-            return RNPStatusDenied;
39
-        case kABAuthorizationStatusRestricted:
40
-            return RNPStatusRestricted;
41
-        default:
42
-            return RNPStatusUndetermined;
43
-    }
44
-#endif
45
-}
46
-
47
-+ (void)request:(void (^)(NSString *))completionHandler
48
-{
49
-    void (^handler)(BOOL, NSError * _Nullable) =  ^(BOOL granted, NSError * _Nullable error) {
50
-        dispatch_async(dispatch_get_main_queue(), ^{
51
-            completionHandler([self.class getStatus]);
52
-        });
53
-    };
54
-    
55
-    
56
-#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
57
-    CNContactStore *contactStore = [[CNContactStore alloc] init];
58
-    [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:handler];
59
-#else
60
-    CFErrorRef error = nil;
61
-    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, &error);
62
-    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
63
-        NSError *err = (__bridge NSError *)error;
64
-        handler(granted, err);
65
-    });
66
-#endif
67
-}
68
-
69
-@end

+ 0
- 17
ios/Permissions/RNPEvent.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPEvent.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPEvent : NSObject
13
-
14
-+ (NSString *)getStatus:(NSString *)type;
15
-+ (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 48
ios/Permissions/RNPEvent.m 查看文件

@@ -1,48 +0,0 @@
1
-//
2
-//  RNPEvent.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPEvent.h"
10
-#import <EventKit/EventKit.h>
11
-
12
-@implementation RNPEvent
13
-
14
-+ (NSString *)getStatus:(NSString *)type
15
-{
16
-    int status = [EKEventStore authorizationStatusForEntityType:[self typeFromString:type]];
17
-
18
-    switch (status) {
19
-        case EKAuthorizationStatusAuthorized:
20
-            return RNPStatusAuthorized;
21
-        case EKAuthorizationStatusDenied:
22
-            return RNPStatusDenied;
23
-        case EKAuthorizationStatusRestricted:
24
-            return RNPStatusRestricted;
25
-        default:
26
-            return RNPStatusUndetermined;
27
-    }
28
-}
29
-
30
-+ (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler
31
-{
32
-    EKEventStore *aStore = [[EKEventStore alloc] init];
33
-    [aStore requestAccessToEntityType:[self typeFromString:type] completion:^(BOOL granted, NSError *error) {
34
-        dispatch_async(dispatch_get_main_queue(), ^{
35
-            completionHandler([self getStatus:type]);
36
-        });
37
-    }];
38
-}
39
-
40
-+(EKEntityType)typeFromString:(NSString *)string {
41
-    if ([string isEqualToString:@"reminder"]) {
42
-        return EKEntityTypeReminder;
43
-    } else {
44
-        return EKEntityTypeEvent;
45
-    }
46
-}
47
-
48
-@end

+ 0
- 17
ios/Permissions/RNPLocation.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPLocation.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPLocation : NSObject
13
-
14
-+ (NSString *)getStatusForType:(NSString *)type;
15
-- (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 78
ios/Permissions/RNPLocation.m 查看文件

@@ -1,78 +0,0 @@
1
-//
2
-//  RNPLocation.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPLocation.h"
10
-#import <CoreLocation/CoreLocation.h>
11
-
12
-
13
-@interface RNPLocation() <CLLocationManagerDelegate>
14
-@property (strong, nonatomic) CLLocationManager* locationManager;
15
-@property (copy) void (^completionHandler)(NSString *);
16
-@end
17
-
18
-@implementation RNPLocation
19
-
20
-+ (NSString *)getStatusForType:(NSString *)type
21
-{
22
-    int status = [CLLocationManager authorizationStatus];
23
-    switch (status) {
24
-        case kCLAuthorizationStatusAuthorizedAlways:
25
-            return RNPStatusAuthorized;
26
-        case kCLAuthorizationStatusAuthorizedWhenInUse:
27
-            return [type isEqualToString:@"always"] ? RNPStatusDenied : RNPStatusAuthorized;
28
-        case kCLAuthorizationStatusDenied:
29
-            return RNPStatusDenied;
30
-        case kCLAuthorizationStatusRestricted:
31
-            return RNPStatusRestricted;
32
-        default:
33
-            return RNPStatusUndetermined;
34
-    }
35
-}
36
-
37
-- (void)request:(NSString*)type completionHandler:(void (^)(NSString *))completionHandler
38
-{
39
-    NSString *status = [RNPLocation getStatusForType:nil];
40
-    if (status == RNPStatusUndetermined) {
41
-        self.completionHandler = completionHandler;
42
-
43
-        if (self.locationManager == nil) {
44
-            self.locationManager = [[CLLocationManager alloc] init];
45
-            self.locationManager.delegate = self;
46
-        }
47
-
48
-        if ([type isEqualToString:@"always"]) {
49
-            [self.locationManager requestAlwaysAuthorization];
50
-        } else {
51
-            [self.locationManager requestWhenInUseAuthorization];
52
-        }
53
-    } else {
54
-        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse && [type isEqualToString:@"always"]) {
55
-            completionHandler(RNPStatusDenied);
56
-        } else {
57
-            completionHandler(status);
58
-        }
59
-    }
60
-}
61
-
62
--(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
63
-    if (status != kCLAuthorizationStatusNotDetermined) {
64
-        if (self.locationManager) {
65
-            self.locationManager.delegate = nil;
66
-            self.locationManager = nil;
67
-        }
68
-
69
-        if (self.completionHandler) {
70
-            //for some reason, checking permission right away returns denied. need to wait a tiny bit
71
-            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
72
-                self.completionHandler([RNPLocation getStatusForType:nil]);
73
-                self.completionHandler = nil;
74
-            });
75
-        }
76
-    }
77
-}
78
-@end

+ 0
- 17
ios/Permissions/RNPMediaLibrary.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPMediaLibrary.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPMediaLibrary : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-+ (void)request:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 41
ios/Permissions/RNPMediaLibrary.m 查看文件

@@ -1,41 +0,0 @@
1
-//
2
-//  RNPPhoto.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPMediaLibrary.h"
10
-#import <MediaPlayer/MediaPlayer.h>
11
-
12
-@implementation RNPMediaLibrary
13
-
14
-+ (NSString *)getStatus
15
-{
16
-    int status = [MPMediaLibrary authorizationStatus];
17
-    switch (status) {
18
-        case MPMediaLibraryAuthorizationStatusAuthorized:
19
-            return RNPStatusAuthorized;
20
-        case MPMediaLibraryAuthorizationStatusDenied:
21
-            return RNPStatusDenied;
22
-        case MPMediaLibraryAuthorizationStatusRestricted:
23
-            return RNPStatusRestricted;
24
-        default:
25
-            return RNPStatusUndetermined;
26
-    }
27
-}
28
-
29
-+ (void)request:(void (^)(NSString *))completionHandler
30
-{
31
-    void (^handler)(void) =  ^(void) {
32
-        dispatch_async(dispatch_get_main_queue(), ^{
33
-            completionHandler([self.class getStatus]);
34
-        });
35
-    };
36
-    
37
-    [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
38
-        handler();
39
-    }];
40
-}
41
-@end

+ 0
- 14
ios/Permissions/RNPMotion.h 查看文件

@@ -1,14 +0,0 @@
1
-//
2
-//  RNPMotion.h
3
-//  ReactNativePermissions
4
-//
5
-
6
-#import <Foundation/Foundation.h>
7
-#import "RCTConvert+RNPStatus.h"
8
-
9
-@interface RNPMotion : NSObject
10
-
11
-+ (NSString *)getStatus;
12
-+ (void)request:(void (^)(NSString *))completionHandler;
13
-
14
-@end

+ 0
- 62
ios/Permissions/RNPMotion.m 查看文件

@@ -1,62 +0,0 @@
1
-//
2
-//  RNPMotion.m
3
-//  ReactNativePermissions
4
-//
5
-
6
-#import "RNPMotion.h"
7
-#import <CoreMotion/CoreMotion.h>
8
-
9
-@implementation RNPMotion
10
-
11
-+ (NSString *)getStatus
12
-{
13
-    if (![CMMotionActivityManager isActivityAvailable]) {
14
-        return RNPStatusRestricted;
15
-    }
16
-    
17
-    if (@available(iOS 11.0, *)) {
18
-        CMAuthorizationStatus status = [CMMotionActivityManager authorizationStatus];
19
-        
20
-        switch (status) {
21
-            case CMAuthorizationStatusAuthorized:
22
-                return RNPStatusAuthorized;
23
-            case CMAuthorizationStatusDenied:
24
-                return RNPStatusDenied;
25
-            case CMAuthorizationStatusNotDetermined:
26
-                return RNPStatusUndetermined;
27
-            case CMAuthorizationStatusRestricted:
28
-                return RNPStatusRestricted;
29
-            default:
30
-                return RNPStatusUndetermined;
31
-        }
32
-    } else {
33
-        return RNPStatusRestricted;
34
-    }
35
-}
36
-
37
-+ (void)request:(void (^)(NSString *))completionHandler
38
-{
39
-    __block NSString *status = [RNPMotion getStatus];
40
-    
41
-    if ([status isEqual: RNPStatusUndetermined]) {
42
-        __block CMMotionActivityManager *activityManager = [[CMMotionActivityManager alloc] init];
43
-        __block NSOperationQueue *motionActivityQueue = [[NSOperationQueue alloc] init];
44
-        [activityManager queryActivityStartingFromDate:[NSDate distantPast] toDate:[NSDate date] toQueue:motionActivityQueue withHandler:^(NSArray *activities, NSError *error) {
45
-            if (error) {
46
-                status = RNPStatusDenied;
47
-            } else if (activities || !error) {
48
-                status = RNPStatusAuthorized;
49
-            }
50
-            
51
-            dispatch_async(dispatch_get_main_queue(), ^{
52
-                completionHandler(status);
53
-            });
54
-            
55
-            activityManager = nil;
56
-            motionActivityQueue = nil;
57
-        }];
58
-    } else {
59
-        completionHandler(status);
60
-    }
61
-}
62
-@end

+ 0
- 17
ios/Permissions/RNPNotification.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPNotification.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPNotification : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-- (void)request:(UIUserNotificationType)types completionHandler:(void (^)(NSString*))completionHandler;
16
-
17
-@end

+ 0
- 70
ios/Permissions/RNPNotification.m 查看文件

@@ -1,70 +0,0 @@
1
-//
2
-//  RNPNotification.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPNotification.h"
10
-
11
-static NSString* RNPDidAskForNotification = @"RNPDidAskForNotification";
12
-
13
-@interface RNPNotification()
14
-@property (copy) void (^completionHandler)(NSString*);
15
-@end
16
-
17
-@implementation RNPNotification
18
-
19
-+ (NSString *)getStatus
20
-{
21
-    BOOL didAskForPermission = [[NSUserDefaults standardUserDefaults] boolForKey:RNPDidAskForNotification];
22
-    BOOL isEnabled = [[[UIApplication sharedApplication] currentUserNotificationSettings] types] != UIUserNotificationTypeNone;
23
-
24
-    if (isEnabled) {
25
-        return RNPStatusAuthorized;
26
-    } else {
27
-        return didAskForPermission ? RNPStatusDenied : RNPStatusUndetermined;
28
-    }
29
-}
30
-
31
-
32
-- (void)request:(UIUserNotificationType)types completionHandler:(void (^)(NSString*))completionHandler
33
-{
34
-    NSString *status = [self.class getStatus];
35
-
36
-    if (status == RNPStatusUndetermined) {
37
-        self.completionHandler = completionHandler;
38
-
39
-        [[NSNotificationCenter defaultCenter] addObserver:self
40
-                                                 selector:@selector(applicationDidBecomeActive)
41
-                                                     name:UIApplicationDidBecomeActiveNotification
42
-                                                   object:nil];
43
-
44
-        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
45
-        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
46
-        [[UIApplication sharedApplication] registerForRemoteNotifications];
47
-
48
-        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:RNPDidAskForNotification];
49
-        [[NSUserDefaults standardUserDefaults] synchronize];
50
-    } else {
51
-        completionHandler(status);
52
-    }
53
-}
54
-
55
-- (void)applicationDidBecomeActive
56
-{
57
-    [[NSNotificationCenter defaultCenter] removeObserver:self
58
-                                                    name:UIApplicationDidBecomeActiveNotification
59
-                                                  object:nil];
60
-
61
-    if (self.completionHandler) {
62
-        //for some reason, checking permission right away returns denied. need to wait a tiny bit
63
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
64
-            self.completionHandler([self.class getStatus]);
65
-            self.completionHandler = nil;
66
-        });
67
-    }
68
-}
69
-
70
-@end

+ 0
- 17
ios/Permissions/RNPPhoto.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPPhoto.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPPhoto : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-+ (void)request:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 43
ios/Permissions/RNPPhoto.m 查看文件

@@ -1,43 +0,0 @@
1
-//
2
-//  RNPPhoto.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 11/07/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPPhoto.h"
10
-#import <AssetsLibrary/AssetsLibrary.h>
11
-
12
-@import Photos;
13
-
14
-@implementation RNPPhoto
15
-
16
-+ (NSString *)getStatus
17
-{
18
-    int status = [PHPhotoLibrary authorizationStatus];
19
-    switch (status) {
20
-        case PHAuthorizationStatusAuthorized:
21
-            return RNPStatusAuthorized;
22
-        case PHAuthorizationStatusDenied:
23
-            return RNPStatusDenied;
24
-        case PHAuthorizationStatusRestricted:
25
-            return RNPStatusRestricted;
26
-        default:
27
-            return RNPStatusUndetermined;
28
-    }
29
-}
30
-
31
-+ (void)request:(void (^)(NSString *))completionHandler
32
-{
33
-    void (^handler)(void) =  ^(void) {
34
-        dispatch_async(dispatch_get_main_queue(), ^{
35
-            completionHandler([self.class getStatus]);
36
-        });
37
-    };
38
-
39
-    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
40
-        handler();
41
-    }];
42
-}
43
-@end

+ 0
- 17
ios/Permissions/RNPSpeechRecognition.h 查看文件

@@ -1,17 +0,0 @@
1
-//
2
-//  RNPSpeechRecognition.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Tres Trantham on 1/11/17.
6
-//  Copyright © 2017 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-#import "RCTConvert+RNPStatus.h"
11
-
12
-@interface RNPSpeechRecognition : NSObject
13
-
14
-+ (NSString *)getStatus;
15
-+ (void)request:(void (^)(NSString *))completionHandler;
16
-
17
-@end

+ 0
- 44
ios/Permissions/RNPSpeechRecognition.m 查看文件

@@ -1,44 +0,0 @@
1
-//
2
-//  RNPSpeechRecognition.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Tres Trantham on 1/11/17.
6
-//  Copyright © 2017 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RNPSpeechRecognition.h"
10
-#import <Speech/Speech.h>
11
-
12
-@implementation RNPSpeechRecognition
13
-
14
-+ (NSString *)getStatus
15
-{
16
-
17
-  int status = [SFSpeechRecognizer authorizationStatus];
18
-
19
-  switch (status) {
20
-      case SFSpeechRecognizerAuthorizationStatusAuthorized:
21
-          return RNPStatusAuthorized;
22
-      case SFSpeechRecognizerAuthorizationStatusDenied:
23
-          return RNPStatusDenied;
24
-      case SFSpeechRecognizerAuthorizationStatusRestricted:
25
-          return RNPStatusRestricted;
26
-      default:
27
-          return RNPStatusUndetermined;
28
-  }
29
-}
30
-
31
-+ (void)request:(void (^)(NSString *))completionHandler
32
-{
33
-    void (^handler)(void) =  ^(void) {
34
-        dispatch_async(dispatch_get_main_queue(), ^{
35
-            completionHandler([self.class getStatus]);
36
-        });
37
-    };
38
-
39
-    [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
40
-        handler();
41
-    }];
42
-}
43
-
44
-@end

+ 0
- 42
ios/RCTConvert+RNPStatus.h 查看文件

@@ -1,42 +0,0 @@
1
-//
2
-//  RCTConvert+RNPStatus
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 23/03/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#if __has_include(<React/RCTConvert.h>)
10
-  #import <React/RCTConvert.h>
11
-#elif __has_include("React/RCTConvert.h")
12
-  #import "React/RCTConvert.h"
13
-#else
14
-  #import "RCTConvert.h"
15
-#endif
16
-
17
-static NSString* RNPStatusUndetermined = @"undetermined";
18
-static NSString* RNPStatusDenied = @"denied";
19
-static NSString* RNPStatusAuthorized = @"authorized";
20
-static NSString* RNPStatusRestricted = @"restricted";
21
-
22
-
23
-typedef NS_ENUM(NSInteger, RNPType) {
24
-    RNPTypeUnknown,
25
-    RNPTypeLocation,
26
-    RNPTypeCamera,
27
-    RNPTypeMicrophone,
28
-    RNPTypePhoto,
29
-    RNPTypeContacts,
30
-    RNPTypeEvent,
31
-    RNPTypeReminder,
32
-    RNPTypeBluetooth,
33
-    RNPTypeNotification,
34
-    RNPTypeBackgroundRefresh,
35
-    RNPTypeSpeechRecognition,
36
-    RNPTypeMediaLibrary,
37
-    RNPTypeMotion
38
-};
39
-
40
-@interface RCTConvert (RNPStatus)
41
-
42
-@end

+ 0
- 29
ios/RCTConvert+RNPStatus.m 查看文件

@@ -1,29 +0,0 @@
1
-//
2
-//  RCTConvert+RNPermissionsStatus.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 23/03/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#import "RCTConvert+RNPStatus.h"
10
-
11
-@implementation RCTConvert (RNPStatus)
12
-
13
-RCT_ENUM_CONVERTER(RNPType, (@{ @"location" : @(RNPTypeLocation),
14
-                                @"camera" : @(RNPTypeCamera),
15
-                                @"microphone" : @(RNPTypeMicrophone),
16
-                                @"photo" : @(RNPTypePhoto),
17
-                                @"contacts" : @(RNPTypeContacts),
18
-                                @"event" : @(RNPTypeEvent),
19
-                                @"reminder" : @(RNPTypeReminder),
20
-                                @"bluetooth" : @(RNPTypeBluetooth),
21
-                                @"notification" : @(RNPTypeNotification),
22
-                                @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
23
-                                @"speechRecognition": @(RNPTypeSpeechRecognition),
24
-                                @"mediaLibrary": @(RNPTypeMediaLibrary),
25
-                                @"motion": @(RNPTypeMotion)
26
-                                }),
27
-                                RNPTypeUnknown, integerValue)
28
-
29
-@end

+ 57
- 0
ios/RCTConvert+RNPermission.h 查看文件

@@ -0,0 +1,57 @@
1
+#import <React/RCTConvert.h>
2
+
3
+typedef NS_ENUM(NSInteger, RNPermission) {
4
+  RNPermissionUnknown = 0,
5
+#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
6
+  RNPermissionBluetoothPeripheral,
7
+#endif
8
+#if __has_include("RNPermissionHandlerCalendars.h")
9
+  RNPermissionCalendars,
10
+#endif
11
+#if __has_include("RNPermissionHandlerCamera.h")
12
+  RNPermissionCamera,
13
+#endif
14
+#if __has_include("RNPermissionHandlerContacts.h")
15
+  RNPermissionContacts,
16
+#endif
17
+#if __has_include("RNPermissionHandlerFaceID.h")
18
+  RNPermissionFaceID,
19
+#endif
20
+#if __has_include("RNPermissionHandlerLocationAlways.h")
21
+  RNPermissionLocationAlways,
22
+#endif
23
+#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
24
+  RNPermissionLocationWhenInUse,
25
+#endif
26
+#if __has_include("RNPermissionHandlerMediaLibrary.h")
27
+  RNPermissionMediaLibrary,
28
+#endif
29
+#if __has_include("RNPermissionHandlerMicrophone.h")
30
+  RNPermissionMicrophone,
31
+#endif
32
+#if __has_include("RNPermissionHandlerMotion.h")
33
+  RNPermissionMotion,
34
+#endif
35
+#if __has_include("RNPermissionHandlerNotifications.h")
36
+  RNPermissionNotifications,
37
+#endif
38
+#if __has_include("RNPermissionHandlerPhotoLibrary.h")
39
+  RNPermissionPhotoLibrary,
40
+#endif
41
+#if __has_include("RNPermissionHandlerReminders.h")
42
+  RNPermissionReminders,
43
+#endif
44
+#if __has_include("RNPermissionHandlerSiri.h")
45
+  RNPermissionSiri,
46
+#endif
47
+#if __has_include("RNPermissionHandlerSpeechRecognition.h")
48
+  RNPermissionSpeechRecognition,
49
+#endif
50
+#if __has_include("RNPermissionHandlerStoreKit.h")
51
+  RNPermissionStoreKit,
52
+#endif
53
+};
54
+
55
+@interface RCTConvert (RNPermission)
56
+
57
+@end

+ 58
- 0
ios/RCTConvert+RNPermission.m 查看文件

@@ -0,0 +1,58 @@
1
+#import "RCTConvert+RNPermission.h"
2
+
3
+@implementation RCTConvert(RNPermission)
4
+
5
+RCT_ENUM_CONVERTER(RNPermission, (@{
6
+#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
7
+  @"BLUETOOTH_PERIPHERICAL": @(RNPermissionBluetoothPeripheral),
8
+#endif
9
+#if __has_include("RNPermissionHandlerCalendars.h")
10
+  @"CALENDARS": @(RNPermissionCalendars),
11
+#endif
12
+#if __has_include("RNPermissionHandlerCamera.h")
13
+  @"CAMERA": @(RNPermissionCamera),
14
+#endif
15
+#if __has_include("RNPermissionHandlerContacts.h")
16
+  @"CONTACTS": @(RNPermissionContacts),
17
+#endif
18
+#if __has_include("RNPermissionHandlerFaceID.h")
19
+  @"FACE_ID": @(RNPermissionFaceID),
20
+#endif
21
+#if __has_include("RNPermissionHandlerLocationAlways.h")
22
+  @"LOCATION_ALWAYS": @(RNPermissionLocationAlways),
23
+#endif
24
+#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
25
+  @"LOCATION_WHEN_IN_USE": @(RNPermissionLocationWhenInUse),
26
+#endif
27
+#if __has_include("RNPermissionHandlerMediaLibrary.h")
28
+  @"MEDIA_LIBRARY": @(RNPermissionMediaLibrary),
29
+#endif
30
+#if __has_include("RNPermissionHandlerMicrophone.h")
31
+  @"MICROPHONE": @(RNPermissionMicrophone),
32
+#endif
33
+#if __has_include("RNPermissionHandlerMotion.h")
34
+  @"MOTION": @(RNPermissionMotion),
35
+#endif
36
+#if __has_include("RNPermissionHandlerNotifications.h")
37
+  @"NOTIFICATIONS": @(RNPermissionNotifications),
38
+#endif
39
+#if __has_include("RNPermissionHandlerPhotoLibrary.h")
40
+  @"PHOTO_LIBRARY": @(RNPermissionPhotoLibrary),
41
+#endif
42
+#if __has_include("RNPermissionHandlerReminders.h")
43
+  @"REMINDERS": @(RNPermissionReminders),
44
+#endif
45
+#if __has_include("RNPermissionHandlerSiri.h")
46
+  @"SIRI": @(RNPermissionSiri),
47
+#endif
48
+#if __has_include("RNPermissionHandlerSpeechRecognition.h")
49
+  @"SPEECH_RECOGNITION": @(RNPermissionSpeechRecognition),
50
+#endif
51
+#if __has_include("RNPermissionHandlerStoreKit.h")
52
+  @"STOREKIT": @(RNPermissionStoreKit),
53
+#endif
54
+}),
55
+  RNPermissionUnknown, integerValue
56
+)
57
+
58
+@end

+ 90
- 4
ios/RNPermissions.podspec 查看文件

@@ -3,7 +3,6 @@ package = JSON.parse(File.read('../package.json'))
3 3
 
4 4
 Pod::Spec.new do |s|
5 5
   s.name                   = "RNPermissions"
6
-  s.dependency               "React"
7 6
 
8 7
   s.version                = package["version"]
9 8
   s.license                = package["license"]
@@ -12,9 +11,96 @@ Pod::Spec.new do |s|
12 11
   s.authors                = package["author"]
13 12
   s.homepage               = package["homepage"]
14 13
 
15
-  s.platform               = :ios, "9.0"
16
-  s.ios.deployment_target  = "9.0"
14
+  s.default_subspec        = "Core"
15
+  s.requires_arc           = true
16
+  s.platforms              = { :ios => "9.0", :tvos => "9.2" }
17
+  s.pod_target_xcconfig    = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++14" }
17 18
 
18 19
   s.source                 = { :git => "#{s.homepage}.git", :tag => s.version }
19
-  s.source_files           = "**/*.{h,m}"
20
+  s.source_files           = "*.{h,m}"
21
+
22
+  s.subspec "Core" do |ss|
23
+    s.dependency              "React/Core"
24
+    ss.source_files         = "*.{h,m}"
25
+  end
26
+
27
+  s.subspec "BluetoothPeripheral" do |ss|
28
+    ss.dependency             "RNPermissions/Core"
29
+    ss.source_files         = "PermissionHandlers/BluetoothPeripheral/*.{h,m}"
30
+  end
31
+
32
+  s.subspec "Calendars" do |ss|
33
+    ss.dependency             "RNPermissions/Core"
34
+    ss.source_files         = "PermissionHandlers/Calendars/*.{h,m}"
35
+  end
36
+
37
+  s.subspec "Camera" do |ss|
38
+    ss.dependency             "RNPermissions/Core"
39
+    ss.source_files         = "PermissionHandlers/Camera/*.{h,m}"
40
+  end
41
+
42
+  s.subspec "Contacts" do |ss|
43
+    ss.dependency             "RNPermissions/Core"
44
+    ss.source_files         = "PermissionHandlers/Contacts/*.{h,m}"
45
+  end
46
+
47
+  s.subspec "FaceID" do |ss|
48
+    ss.dependency             "RNPermissions/Core"
49
+    ss.source_files         = "PermissionHandlers/FaceID/*.{h,m}"
50
+  end
51
+
52
+  s.subspec "LocationAlways" do |ss|
53
+    ss.dependency             "RNPermissions/Core"
54
+    ss.source_files         = "PermissionHandlers/LocationAlways/*.{h,m}"
55
+  end
56
+
57
+  s.subspec "LocationWhenInUse" do |ss|
58
+    ss.dependency             "RNPermissions/Core"
59
+    ss.source_files         = "PermissionHandlers/LocationWhenInUse/*.{h,m}"
60
+  end
61
+
62
+  s.subspec "MediaLibrary" do |ss|
63
+    ss.dependency             "RNPermissions/Core"
64
+    ss.source_files         = "PermissionHandlers/MediaLibrary/*.{h,m}"
65
+  end
66
+
67
+  s.subspec "Microphone" do |ss|
68
+    ss.dependency             "RNPermissions/Core"
69
+    ss.source_files         = "PermissionHandlers/Microphone/*.{h,m}"
70
+  end
71
+
72
+  s.subspec "Motion" do |ss|
73
+    ss.dependency             "RNPermissions/Core"
74
+    ss.source_files         = "PermissionHandlers/Motion/*.{h,m}"
75
+  end
76
+
77
+  s.subspec "Notifications" do |ss|
78
+    ss.dependency             "RNPermissions/Core"
79
+    ss.source_files         = "PermissionHandlers/Notifications/*.{h,m}"
80
+  end
81
+
82
+  s.subspec "PhotoLibrary" do |ss|
83
+    ss.dependency             "RNPermissions/Core"
84
+    ss.source_files         = "PermissionHandlers/PhotoLibrary/*.{h,m}"
85
+  end
86
+
87
+  s.subspec "Reminders" do |ss|
88
+    ss.dependency             "RNPermissions/Core"
89
+    ss.source_files         = "PermissionHandlers/Reminders/*.{h,m}"
90
+  end
91
+
92
+  s.subspec "Siri" do |ss|
93
+    ss.dependency             "RNPermissions/Core"
94
+    ss.source_files         = "PermissionHandlers/Siri/*.{h,m}"
95
+  end
96
+
97
+  s.subspec "SpeechRecognition" do |ss|
98
+    ss.dependency             "RNPermissions/Core"
99
+    ss.source_files         = "PermissionHandlers/SpeechRecognition/*.{h,m}"
100
+  end
101
+
102
+  s.subspec "StoreKit" do |ss|
103
+    ss.dependency             "RNPermissions/Core"
104
+    ss.source_files         = "PermissionHandlers/StoreKit/*.{h,m}"
105
+  end
20 106
 end

+ 310
- 0
ios/RNPermissions.xcodeproj/project.pbxproj 查看文件

@@ -0,0 +1,310 @@
1
+// !$*UTF8*$!
2
+{
3
+	archiveVersion = 1;
4
+	classes = {
5
+	};
6
+	objectVersion = 46;
7
+	objects = {
8
+
9
+/* Begin PBXBuildFile section */
10
+		66EEFEBE1F217A9E0021D48A /* RNPermissionsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 66EEFEBD1F217A9E0021D48A /* RNPermissionsManager.m */; };
11
+		66EEFEBF1F217A9E0021D48A /* RNPermissionsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 66EEFEBD1F217A9E0021D48A /* RNPermissionsManager.m */; };
12
+		DD4F8BE52200C51A009134C7 /* RCTConvert+RNPermission.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4F8BE32200C51A009134C7 /* RCTConvert+RNPermission.m */; };
13
+/* End PBXBuildFile section */
14
+
15
+/* Begin PBXFileReference section */
16
+		134814201AA4EA6300B7C361 /* libRNPermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNPermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
17
+		2D2A28471D9B043800D4039D /* libRNPermissions-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNPermissions-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
18
+		66EEFEBC1F217A9E0021D48A /* RNPermissionsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPermissionsManager.h; sourceTree = "<group>"; };
19
+		66EEFEBD1F217A9E0021D48A /* RNPermissionsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPermissionsManager.m; sourceTree = "<group>"; };
20
+		DD4F8BE32200C51A009134C7 /* RCTConvert+RNPermission.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPermission.m"; sourceTree = "<group>"; };
21
+		DD4F8BE42200C51A009134C7 /* RCTConvert+RNPermission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+RNPermission.h"; sourceTree = "<group>"; };
22
+/* End PBXFileReference section */
23
+
24
+/* Begin PBXGroup section */
25
+		134814211AA4EA7D00B7C361 /* Products */ = {
26
+			isa = PBXGroup;
27
+			children = (
28
+				134814201AA4EA6300B7C361 /* libRNPermissions.a */,
29
+			);
30
+			name = Products;
31
+			sourceTree = "<group>";
32
+		};
33
+		58B511D21A9E6C8500147676 = {
34
+			isa = PBXGroup;
35
+			children = (
36
+				DD4F8BE42200C51A009134C7 /* RCTConvert+RNPermission.h */,
37
+				DD4F8BE32200C51A009134C7 /* RCTConvert+RNPermission.m */,
38
+				66EEFEBC1F217A9E0021D48A /* RNPermissionsManager.h */,
39
+				66EEFEBD1F217A9E0021D48A /* RNPermissionsManager.m */,
40
+				134814211AA4EA7D00B7C361 /* Products */,
41
+				2D2A28471D9B043800D4039D /* libRNPermissions-tvOS.a */,
42
+			);
43
+			indentWidth = 2;
44
+			sourceTree = "<group>";
45
+			tabWidth = 2;
46
+		};
47
+/* End PBXGroup section */
48
+
49
+/* Begin PBXNativeTarget section */
50
+		2D2A28461D9B043800D4039D /* RNPermissions-tvOS */ = {
51
+			isa = PBXNativeTarget;
52
+			buildConfigurationList = 2D2A284F1D9B043800D4039D /* Build configuration list for PBXNativeTarget "RNPermissions-tvOS" */;
53
+			buildPhases = (
54
+				2D2A28431D9B043800D4039D /* Sources */,
55
+			);
56
+			buildRules = (
57
+			);
58
+			dependencies = (
59
+			);
60
+			name = "RNPermissions-tvOS";
61
+			productName = "RNPermissions-tvOS";
62
+			productReference = 2D2A28471D9B043800D4039D /* libRNPermissions-tvOS.a */;
63
+			productType = "com.apple.product-type.library.static";
64
+		};
65
+		58B511DA1A9E6C8500147676 /* RNPermissions */ = {
66
+			isa = PBXNativeTarget;
67
+			buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNPermissions" */;
68
+			buildPhases = (
69
+				58B511D71A9E6C8500147676 /* Sources */,
70
+			);
71
+			buildRules = (
72
+			);
73
+			dependencies = (
74
+			);
75
+			name = RNPermissions;
76
+			productName = RCTDataManager;
77
+			productReference = 134814201AA4EA6300B7C361 /* libRNPermissions.a */;
78
+			productType = "com.apple.product-type.library.static";
79
+		};
80
+/* End PBXNativeTarget section */
81
+
82
+/* Begin PBXProject section */
83
+		58B511D31A9E6C8500147676 /* Project object */ = {
84
+			isa = PBXProject;
85
+			attributes = {
86
+				LastUpgradeCheck = 0610;
87
+				ORGANIZATIONNAME = Facebook;
88
+				TargetAttributes = {
89
+					2D2A28461D9B043800D4039D = {
90
+						CreatedOnToolsVersion = 8.0;
91
+						ProvisioningStyle = Automatic;
92
+					};
93
+					58B511DA1A9E6C8500147676 = {
94
+						CreatedOnToolsVersion = 6.1.1;
95
+					};
96
+				};
97
+			};
98
+			buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNPermissions" */;
99
+			compatibilityVersion = "Xcode 3.2";
100
+			developmentRegion = English;
101
+			hasScannedForEncodings = 0;
102
+			knownRegions = (
103
+				en,
104
+			);
105
+			mainGroup = 58B511D21A9E6C8500147676;
106
+			productRefGroup = 58B511D21A9E6C8500147676;
107
+			projectDirPath = "";
108
+			projectRoot = "";
109
+			targets = (
110
+				58B511DA1A9E6C8500147676 /* RNPermissions */,
111
+				2D2A28461D9B043800D4039D /* RNPermissions-tvOS */,
112
+			);
113
+		};
114
+/* End PBXProject section */
115
+
116
+/* Begin PBXSourcesBuildPhase section */
117
+		2D2A28431D9B043800D4039D /* Sources */ = {
118
+			isa = PBXSourcesBuildPhase;
119
+			buildActionMask = 2147483647;
120
+			files = (
121
+				66EEFEBF1F217A9E0021D48A /* RNPermissionsManager.m in Sources */,
122
+			);
123
+			runOnlyForDeploymentPostprocessing = 0;
124
+		};
125
+		58B511D71A9E6C8500147676 /* Sources */ = {
126
+			isa = PBXSourcesBuildPhase;
127
+			buildActionMask = 2147483647;
128
+			files = (
129
+				DD4F8BE52200C51A009134C7 /* RCTConvert+RNPermission.m in Sources */,
130
+				66EEFEBE1F217A9E0021D48A /* RNPermissionsManager.m in Sources */,
131
+			);
132
+			runOnlyForDeploymentPostprocessing = 0;
133
+		};
134
+/* End PBXSourcesBuildPhase section */
135
+
136
+/* Begin XCBuildConfiguration section */
137
+		2D2A284D1D9B043800D4039D /* Debug */ = {
138
+			isa = XCBuildConfiguration;
139
+			buildSettings = {
140
+				CLANG_ANALYZER_NONNULL = YES;
141
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
142
+				CLANG_WARN_INFINITE_RECURSION = YES;
143
+				CLANG_WARN_SUSPICIOUS_MOVES = YES;
144
+				DEBUG_INFORMATION_FORMAT = dwarf;
145
+				ENABLE_TESTABILITY = YES;
146
+				GCC_NO_COMMON_BLOCKS = YES;
147
+				OTHER_LDFLAGS = "-ObjC";
148
+				PRODUCT_NAME = "$(TARGET_NAME)";
149
+				SDKROOT = appletvos;
150
+				TVOS_DEPLOYMENT_TARGET = 9.2;
151
+			};
152
+			name = Debug;
153
+		};
154
+		2D2A284E1D9B043800D4039D /* Release */ = {
155
+			isa = XCBuildConfiguration;
156
+			buildSettings = {
157
+				CLANG_ANALYZER_NONNULL = YES;
158
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
159
+				CLANG_WARN_INFINITE_RECURSION = YES;
160
+				CLANG_WARN_SUSPICIOUS_MOVES = YES;
161
+				COPY_PHASE_STRIP = NO;
162
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
163
+				GCC_NO_COMMON_BLOCKS = YES;
164
+				OTHER_LDFLAGS = "-ObjC";
165
+				PRODUCT_NAME = "$(TARGET_NAME)";
166
+				SDKROOT = appletvos;
167
+				TVOS_DEPLOYMENT_TARGET = 9.2;
168
+			};
169
+			name = Release;
170
+		};
171
+		58B511ED1A9E6C8500147676 /* Debug */ = {
172
+			isa = XCBuildConfiguration;
173
+			buildSettings = {
174
+				ALWAYS_SEARCH_USER_PATHS = NO;
175
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
176
+				CLANG_CXX_LIBRARY = "libc++";
177
+				CLANG_ENABLE_MODULES = YES;
178
+				CLANG_ENABLE_OBJC_ARC = YES;
179
+				CLANG_WARN_BOOL_CONVERSION = YES;
180
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
181
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
182
+				CLANG_WARN_EMPTY_BODY = YES;
183
+				CLANG_WARN_ENUM_CONVERSION = YES;
184
+				CLANG_WARN_INT_CONVERSION = YES;
185
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
186
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
187
+				CLANG_WARN_UNREACHABLE_CODE = YES;
188
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
189
+				COPY_PHASE_STRIP = NO;
190
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
191
+				GCC_C_LANGUAGE_STANDARD = gnu99;
192
+				GCC_DYNAMIC_NO_PIC = NO;
193
+				GCC_OPTIMIZATION_LEVEL = 0;
194
+				GCC_PREPROCESSOR_DEFINITIONS = (
195
+					"DEBUG=1",
196
+					"$(inherited)",
197
+				);
198
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
199
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
200
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
201
+				GCC_WARN_SHADOW = YES;
202
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
203
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
204
+				GCC_WARN_UNUSED_FUNCTION = YES;
205
+				GCC_WARN_UNUSED_VARIABLE = YES;
206
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
207
+				MTL_ENABLE_DEBUG_INFO = YES;
208
+				ONLY_ACTIVE_ARCH = YES;
209
+				SDKROOT = iphoneos;
210
+				SKIP_INSTALL = YES;
211
+				WARNING_CFLAGS = (
212
+					"-Werror",
213
+					"-Wall",
214
+				);
215
+			};
216
+			name = Debug;
217
+		};
218
+		58B511EE1A9E6C8500147676 /* Release */ = {
219
+			isa = XCBuildConfiguration;
220
+			buildSettings = {
221
+				ALWAYS_SEARCH_USER_PATHS = NO;
222
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
223
+				CLANG_CXX_LIBRARY = "libc++";
224
+				CLANG_ENABLE_MODULES = YES;
225
+				CLANG_ENABLE_OBJC_ARC = YES;
226
+				CLANG_WARN_BOOL_CONVERSION = YES;
227
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
228
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
229
+				CLANG_WARN_EMPTY_BODY = YES;
230
+				CLANG_WARN_ENUM_CONVERSION = YES;
231
+				CLANG_WARN_INT_CONVERSION = YES;
232
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
233
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
234
+				CLANG_WARN_UNREACHABLE_CODE = YES;
235
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
236
+				COPY_PHASE_STRIP = YES;
237
+				ENABLE_NS_ASSERTIONS = NO;
238
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
239
+				GCC_C_LANGUAGE_STANDARD = gnu99;
240
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
241
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
242
+				GCC_WARN_SHADOW = YES;
243
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
244
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
245
+				GCC_WARN_UNUSED_FUNCTION = YES;
246
+				GCC_WARN_UNUSED_VARIABLE = YES;
247
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
248
+				MTL_ENABLE_DEBUG_INFO = NO;
249
+				SDKROOT = iphoneos;
250
+				SKIP_INSTALL = YES;
251
+				VALIDATE_PRODUCT = YES;
252
+				WARNING_CFLAGS = (
253
+					"-Werror",
254
+					"-Wall",
255
+				);
256
+			};
257
+			name = Release;
258
+		};
259
+		58B511F01A9E6C8500147676 /* Debug */ = {
260
+			isa = XCBuildConfiguration;
261
+			buildSettings = {
262
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
263
+				OTHER_LDFLAGS = "-ObjC";
264
+				PRODUCT_NAME = "$(TARGET_NAME)";
265
+			};
266
+			name = Debug;
267
+		};
268
+		58B511F11A9E6C8500147676 /* Release */ = {
269
+			isa = XCBuildConfiguration;
270
+			buildSettings = {
271
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
272
+				OTHER_LDFLAGS = "-ObjC";
273
+				PRODUCT_NAME = "$(TARGET_NAME)";
274
+			};
275
+			name = Release;
276
+		};
277
+/* End XCBuildConfiguration section */
278
+
279
+/* Begin XCConfigurationList section */
280
+		2D2A284F1D9B043800D4039D /* Build configuration list for PBXNativeTarget "RNPermissions-tvOS" */ = {
281
+			isa = XCConfigurationList;
282
+			buildConfigurations = (
283
+				2D2A284D1D9B043800D4039D /* Debug */,
284
+				2D2A284E1D9B043800D4039D /* Release */,
285
+			);
286
+			defaultConfigurationIsVisible = 0;
287
+			defaultConfigurationName = Release;
288
+		};
289
+		58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RNPermissions" */ = {
290
+			isa = XCConfigurationList;
291
+			buildConfigurations = (
292
+				58B511ED1A9E6C8500147676 /* Debug */,
293
+				58B511EE1A9E6C8500147676 /* Release */,
294
+			);
295
+			defaultConfigurationIsVisible = 0;
296
+			defaultConfigurationName = Release;
297
+		};
298
+		58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RNPermissions" */ = {
299
+			isa = XCConfigurationList;
300
+			buildConfigurations = (
301
+				58B511F01A9E6C8500147676 /* Debug */,
302
+				58B511F11A9E6C8500147676 /* Release */,
303
+			);
304
+			defaultConfigurationIsVisible = 0;
305
+			defaultConfigurationName = Release;
306
+		};
307
+/* End XCConfigurationList section */
308
+	};
309
+	rootObject = 58B511D31A9E6C8500147676 /* Project object */;
310
+}

+ 36
- 0
ios/RNPermissionsManager.h 查看文件

@@ -0,0 +1,36 @@
1
+#import <React/RCTBridgeModule.h>
2
+
3
+typedef enum {
4
+  RNPermissionStatusNotAvailable = 0,
5
+  RNPermissionStatusNotDetermined = 1,
6
+  RNPermissionStatusRestricted = 2,
7
+  RNPermissionStatusDenied = 3,
8
+  RNPermissionStatusAuthorized = 4,
9
+} RNPermissionStatus;
10
+
11
+@protocol RNPermissionHandler <NSObject>
12
+
13
+@optional
14
+
15
++ (NSArray<NSString *> * _Nullable)usageDescriptionKeys;
16
+
17
+@required
18
+
19
+- (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
20
+             withRejecter:(void (^)(NSError *error))reject;
21
+
22
+- (void)requestWithOptions:(NSDictionary * _Nullable)options
23
+              withResolver:(void (^)(RNPermissionStatus status))resolve
24
+              withRejecter:(void (^)(NSError *error))reject;
25
+
26
+@end
27
+
28
+@interface RNPermissionsManager : NSObject <RCTBridgeModule>
29
+
30
++ (bool)hasBackgroundModeEnabled:(NSString *)mode;
31
+
32
++ (void)logErrorMessage:(NSString *)message;
33
+
34
++ (bool)hasBeenRequestedOnce:(id<RNPermissionHandler>)handler;
35
+
36
+@end

+ 258
- 0
ios/RNPermissionsManager.m 查看文件

@@ -0,0 +1,258 @@
1
+#import "RNPermissionsManager.h"
2
+#import "RCTConvert+RNPermission.h"
3
+
4
+#import <React/RCTLog.h>
5
+
6
+#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
7
+#import "RNPermissionHandlerBluetoothPeripheral.h"
8
+#endif
9
+#if __has_include("RNPermissionHandlerCalendars.h")
10
+#import "RNPermissionHandlerCalendars.h"
11
+#endif
12
+#if __has_include("RNPermissionHandlerCamera.h")
13
+#import "RNPermissionHandlerCamera.h"
14
+#endif
15
+#if __has_include("RNPermissionHandlerContacts.h")
16
+#import "RNPermissionHandlerContacts.h"
17
+#endif
18
+#if __has_include("RNPermissionHandlerFaceID.h")
19
+#import "RNPermissionHandlerFaceID.h"
20
+#endif
21
+#if __has_include("RNPermissionHandlerLocationAlways.h")
22
+#import "RNPermissionHandlerLocationAlways.h"
23
+#endif
24
+#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
25
+#import "RNPermissionHandlerLocationWhenInUse.h"
26
+#endif
27
+#if __has_include("RNPermissionHandlerMediaLibrary.h")
28
+#import "RNPermissionHandlerMediaLibrary.h"
29
+#endif
30
+#if __has_include("RNPermissionHandlerMicrophone.h")
31
+#import "RNPermissionHandlerMicrophone.h"
32
+#endif
33
+#if __has_include("RNPermissionHandlerMotion.h")
34
+#import "RNPermissionHandlerMotion.h"
35
+#endif
36
+#if __has_include("RNPermissionHandlerNotifications.h")
37
+#import "RNPermissionHandlerNotifications.h"
38
+#endif
39
+#if __has_include("RNPermissionHandlerPhotoLibrary.h")
40
+#import "RNPermissionHandlerPhotoLibrary.h"
41
+#endif
42
+#if __has_include("RNPermissionHandlerReminders.h")
43
+#import "RNPermissionHandlerReminders.h"
44
+#endif
45
+#if __has_include("RNPermissionHandlerSiri.h")
46
+#import "RNPermissionHandlerSiri.h"
47
+#endif
48
+#if __has_include("RNPermissionHandlerSpeechRecognition.h")
49
+#import "RNPermissionHandlerSpeechRecognition.h"
50
+#endif
51
+#if __has_include("RNPermissionHandlerStoreKit.h")
52
+#import "RNPermissionHandlerStoreKit.h"
53
+#endif
54
+
55
+static NSString* requestedKey = @"requested-permissions";
56
+
57
+@implementation RNPermissionsManager
58
+
59
+RCT_EXPORT_MODULE(RNPermissions);
60
+
61
++ (BOOL)requiresMainQueueSetup {
62
+  return YES;
63
+}
64
+
65
+- (dispatch_queue_t)methodQueue {
66
+  return dispatch_get_main_queue();
67
+}
68
+
69
+- (id<RNPermissionHandler> _Nullable)handlerForPermission:(RNPermission)permission {
70
+  id<RNPermissionHandler> handler = nil;
71
+
72
+  switch (permission) {
73
+#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
74
+    case RNPermissionBluetoothPeripheral:
75
+      handler = [RNPermissionHandlerBluetoothPeripheral new];
76
+      break;
77
+#endif
78
+#if __has_include("RNPermissionHandlerCalendars.h")
79
+    case RNPermissionCalendars:
80
+      handler = [RNPermissionHandlerCalendars new];
81
+      break;
82
+#endif
83
+#if __has_include("RNPermissionHandlerCamera.h")
84
+    case RNPermissionCamera:
85
+      handler = [RNPermissionHandlerCamera new];
86
+      break;
87
+#endif
88
+#if __has_include("RNPermissionHandlerContacts.h")
89
+    case RNPermissionContacts:
90
+      handler = [RNPermissionHandlerContacts new];
91
+      break;
92
+#endif
93
+#if __has_include("RNPermissionHandlerFaceID.h")
94
+    case RNPermissionFaceID:
95
+      handler = [RNPermissionHandlerFaceID new];
96
+      break;
97
+#endif
98
+#if __has_include("RNPermissionHandlerLocationAlways.h")
99
+    case RNPermissionLocationAlways:
100
+      handler = [RNPermissionHandlerLocationAlways new];
101
+      break;
102
+#endif
103
+#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
104
+    case RNPermissionLocationWhenInUse:
105
+      handler = [RNPermissionHandlerLocationWhenInUse new];
106
+      break;
107
+#endif
108
+#if __has_include("RNPermissionHandlerMediaLibrary.h")
109
+    case RNPermissionMediaLibrary:
110
+      handler = [RNPermissionHandlerMediaLibrary new];
111
+      break;
112
+#endif
113
+#if __has_include("RNPermissionHandlerMicrophone.h")
114
+    case RNPermissionMicrophone:
115
+      handler = [RNPermissionHandlerMicrophone new];
116
+      break;
117
+#endif
118
+#if __has_include("RNPermissionHandlerMotion.h")
119
+    case RNPermissionMotion:
120
+      handler = [RNPermissionHandlerMotion new];
121
+      break;
122
+#endif
123
+#if __has_include("RNPermissionHandlerNotifications.h")
124
+    case RNPermissionNotifications:
125
+      handler = [RNPermissionHandlerNotifications new];
126
+      break;
127
+#endif
128
+#if __has_include("RNPermissionHandlerPhotoLibrary.h")
129
+    case RNPermissionPhotoLibrary:
130
+      handler = [RNPermissionHandlerPhotoLibrary new];
131
+      break;
132
+#endif
133
+#if __has_include("RNPermissionHandlerReminders.h")
134
+    case RNPermissionReminders:
135
+      handler = [RNPermissionHandlerReminders new];
136
+      break;
137
+#endif
138
+#if __has_include("RNPermissionHandlerSiri.h")
139
+    case RNPermissionSiri:
140
+      handler = [RNPermissionHandlerSiri new];
141
+      break;
142
+#endif
143
+#if __has_include("RNPermissionHandlerSpeechRecognition.h")
144
+    case RNPermissionSpeechRecognition:
145
+      handler = [RNPermissionHandlerSpeechRecognition new];
146
+      break;
147
+#endif
148
+#if __has_include("RNPermissionHandlerStoreKit.h")
149
+    case RNPermissionStoreKit:
150
+      handler = [RNPermissionHandlerStoreKit new];
151
+      break;
152
+#endif
153
+    case RNPermissionUnknown:
154
+      break; // RCTConvert prevents this case
155
+  }
156
+
157
+#if RCT_DEV
158
+  if (handler != nil && [[handler class] respondsToSelector:@selector(usageDescriptionKeys)]) {
159
+    NSArray<NSString *> *usageDescriptionKeys = [[handler class] usageDescriptionKeys];
160
+
161
+    if (usageDescriptionKeys != nil) {
162
+      for (NSString *key in usageDescriptionKeys) {
163
+        if (![[NSBundle mainBundle] objectForInfoDictionaryKey:key]) {
164
+          RCTLogError(@"Cannot check or request permission without the required \"%@\" entry in your app \"Info.plist\" file.", key);
165
+          return nil;
166
+        }
167
+      }
168
+    }
169
+  }
170
+#endif
171
+
172
+  return handler;
173
+}
174
+
175
+- (NSString *)stringForStatus:(RNPermissionStatus)status {
176
+  switch (status) {
177
+    case RNPermissionStatusNotAvailable:
178
+    case RNPermissionStatusRestricted:
179
+      return @"unavailable";
180
+    case RNPermissionStatusNotDetermined:
181
+      return @"denied";
182
+    case RNPermissionStatusDenied:
183
+      return @"never_ask_again";
184
+    case RNPermissionStatusAuthorized:
185
+      return @"granted";
186
+  }
187
+}
188
+
189
++ (bool)hasBackgroundModeEnabled:(NSString *)mode {
190
+  NSArray *modes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
191
+  return [modes isKindOfClass:[NSArray class]] && [modes containsObject:mode];
192
+}
193
+
194
++ (void)logErrorMessage:(NSString *)message {
195
+  RCTLogError(@"%@", message);
196
+}
197
+
198
++ (bool)hasBeenRequestedOnce:(id<RNPermissionHandler>)handler {
199
+  NSArray *requested = [[NSUserDefaults standardUserDefaults] arrayForKey:requestedKey];
200
+  return [requested containsObject:NSStringFromClass([handler class])];
201
+}
202
+
203
+RCT_REMAP_METHOD(openSettings,
204
+                 openSettingsWithResolver:(RCTPromiseResolveBlock)resolve
205
+                 withRejecter:(RCTPromiseRejectBlock)reject) {
206
+  UIApplication *sharedApplication = [UIApplication sharedApplication];
207
+  NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
208
+
209
+  if ([sharedApplication canOpenURL:url]) {
210
+    [sharedApplication openURL:url];
211
+    resolve(@(true));
212
+  } else {
213
+    reject(@"cannot_open_settings", @"Cannot open application settings.", nil);
214
+  }
215
+}
216
+
217
+RCT_REMAP_METHOD(check,
218
+                 checkWithPermission:(RNPermission)permission
219
+                 withResolver:(RCTPromiseResolveBlock)resolve
220
+                 withRejecter:(RCTPromiseRejectBlock)reject) {
221
+  id<RNPermissionHandler> handler = [self handlerForPermission:permission];
222
+
223
+  [handler checkWithResolver:^(RNPermissionStatus status) {
224
+    resolve([self stringForStatus:status]);
225
+  } withRejecter:^(NSError *error) {
226
+    reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
227
+  }];
228
+}
229
+
230
+RCT_REMAP_METHOD(request,
231
+                 requestWithPermission:(RNPermission)permission
232
+                 withOptions:(NSDictionary * _Nullable)options
233
+                 withResolver:(RCTPromiseResolveBlock)resolve
234
+                 withRejecter:(RCTPromiseRejectBlock)reject) {
235
+  id<RNPermissionHandler> handler = [self handlerForPermission:permission];
236
+
237
+  [handler requestWithOptions:options withResolver:^(RNPermissionStatus status) {
238
+    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
239
+    NSString *handlerClassName = NSStringFromClass([handler class]);
240
+    NSMutableArray *requested = [[userDefaults arrayForKey:requestedKey] mutableCopy];
241
+
242
+    if (requested == nil) {
243
+      requested = [NSMutableArray new];
244
+    }
245
+
246
+    if (![requested containsObject:handlerClassName]) {
247
+      [requested addObject:handlerClassName];
248
+      [userDefaults setObject:requested forKey:requestedKey];
249
+      [userDefaults synchronize];
250
+    }
251
+
252
+    resolve([self stringForStatus:status]);
253
+  } withRejecter:^(NSError *error) {
254
+    reject([NSString stringWithFormat:@"%ld", error.code], error.localizedDescription, error);
255
+  }];
256
+}
257
+
258
+@end

+ 0
- 19
ios/ReactNativePermissions.h 查看文件

@@ -1,19 +0,0 @@
1
-//
2
-//  ReactNativePermissions.h
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 18/02/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-#if __has_include(<React/RCTBridgeModule.h>)
10
-  #import <React/RCTBridgeModule.h>
11
-#elif __has_include("React/RCTBridgeModule.h")
12
-  #import "React/RCTBridgeModule.h"
13
-#else
14
-  #import "RCTBridgeModule.h"
15
-#endif
16
-
17
-@interface ReactNativePermissions : NSObject <RCTBridgeModule>
18
-
19
-@end

+ 0
- 247
ios/ReactNativePermissions.m 查看文件

@@ -1,247 +0,0 @@
1
-//
2
-//  ReactNativePermissions.m
3
-//  ReactNativePermissions
4
-//
5
-//  Created by Yonah Forst on 18/02/16.
6
-//  Copyright © 2016 Yonah Forst. All rights reserved.
7
-//
8
-
9
-@import Contacts;
10
-
11
-#import "ReactNativePermissions.h"
12
-
13
-#if __has_include(<React/RCTBridge.h>)
14
-  #import <React/RCTBridge.h>
15
-#elif __has_include("React/RCTBridge.h")
16
-  #import "React/RCTBridge.h"
17
-#else
18
-  #import "RCTBridge.h"
19
-#endif
20
-
21
-#if __has_include(<React/RCTConvert.h>)
22
-  #import <React/RCTConvert.h>
23
-#elif __has_include("React/RCTConvert.h")
24
-  #import "React/RCTConvert.h"
25
-#else
26
-  #import "RCTConvert.h"
27
-#endif
28
-
29
-#if __has_include(<React/RCTEventDispatcher.h>)
30
-  #import <React/RCTEventDispatcher.h>
31
-#elif __has_include("React/RCTEventDispatcher.h")
32
-  #import "React/RCTEventDispatcher.h"
33
-#else
34
-  #import "RCTEventDispatcher.h"
35
-#endif
36
-
37
-#import "RNPLocation.h"
38
-#import "RNPBluetooth.h"
39
-#import "RNPNotification.h"
40
-#import "RNPAudioVideo.h"
41
-#import "RNPEvent.h"
42
-#import "RNPPhoto.h"
43
-#import "RNPContacts.h"
44
-#import "RNPBackgroundRefresh.h"
45
-#import "RNPSpeechRecognition.h"
46
-#import "RNPMediaLibrary.h"
47
-#import "RNPMotion.h"
48
-
49
-
50
-@interface ReactNativePermissions()
51
-@property (strong, nonatomic) RNPLocation *locationMgr;
52
-@property (strong, nonatomic) RNPNotification *notificationMgr;
53
-@property (strong, nonatomic) RNPBluetooth *bluetoothMgr;
54
-@end
55
-
56
-@implementation ReactNativePermissions
57
-
58
-
59
-RCT_EXPORT_MODULE();
60
-@synthesize bridge = _bridge;
61
-
62
-+ (BOOL)requiresMainQueueSetup
63
-{
64
-    return YES;
65
-}
66
-
67
-#pragma mark Initialization
68
-
69
-- (instancetype)init
70
-{
71
-    if (self = [super init]) {
72
-    }
73
-
74
-    return self;
75
-}
76
-
77
-/**
78
- * run on the main queue.
79
- */
80
-- (dispatch_queue_t)methodQueue {
81
-    return dispatch_get_main_queue();
82
-}
83
-
84
-
85
-RCT_REMAP_METHOD(canOpenSettings, canOpenSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
86
-{
87
-    resolve(@(UIApplicationOpenSettingsURLString != nil));
88
-}
89
-
90
-
91
-RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
92
-{
93
-    if (@(UIApplicationOpenSettingsURLString != nil)) {
94
-
95
-        NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
96
-        id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
97
-                                               object:nil
98
-                                                queue:nil
99
-                                           usingBlock:^(NSNotification *note) {
100
-                                               [center removeObserver:token];
101
-                                               resolve(@YES);
102
-                                           }];
103
-
104
-        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
105
-        [[UIApplication sharedApplication] openURL:url];
106
-    }
107
-}
108
-
109
-
110
-RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
111
-{
112
-    NSString *status;
113
-
114
-    switch (type) {
115
-
116
-        case RNPTypeLocation: {
117
-            NSString *locationPermissionType = [RCTConvert NSString:json];
118
-            status = [RNPLocation getStatusForType:locationPermissionType];
119
-            break;
120
-        }
121
-        case RNPTypeCamera:
122
-            status = [RNPAudioVideo getStatus:@"video"];
123
-            break;
124
-        case RNPTypeMicrophone:
125
-            status = [RNPAudioVideo getStatus:@"audio"];
126
-            break;
127
-        case RNPTypePhoto:
128
-            status = [RNPPhoto getStatus];
129
-            break;
130
-        case RNPTypeContacts:
131
-            status = [RNPContacts getStatus];
132
-            break;
133
-        case RNPTypeEvent:
134
-            status = [RNPEvent getStatus:@"event"];
135
-            break;
136
-        case RNPTypeReminder:
137
-            status = [RNPEvent getStatus:@"reminder"];
138
-            break;
139
-        case RNPTypeBluetooth:
140
-            status = [RNPBluetooth getStatus];
141
-            break;
142
-        case RNPTypeNotification:
143
-            status = [RNPNotification getStatus];
144
-            break;
145
-        case RNPTypeBackgroundRefresh:
146
-            status = [RNPBackgroundRefresh getStatus];
147
-            break;
148
-        case RNPTypeSpeechRecognition:
149
-            status = [RNPSpeechRecognition getStatus];
150
-            break;
151
-        case RNPTypeMediaLibrary:
152
-            status = [RNPMediaLibrary getStatus];
153
-            break;
154
-        case RNPTypeMotion:
155
-            status = [RNPMotion getStatus];
156
-            break;
157
-        default:
158
-            break;
159
-    }
160
-
161
-    resolve(status);
162
-}
163
-
164
-RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
165
-{
166
-    NSString *status;
167
-
168
-    switch (type) {
169
-        case RNPTypeLocation:
170
-            return [self requestLocation:json resolve:resolve];
171
-        case RNPTypeCamera:
172
-            return [RNPAudioVideo request:@"video" completionHandler:resolve];
173
-        case RNPTypeMicrophone:
174
-            return [RNPAudioVideo request:@"audio" completionHandler:resolve];
175
-        case RNPTypePhoto:
176
-            return [RNPPhoto request:resolve];
177
-        case RNPTypeContacts:
178
-            return [RNPContacts request:resolve];
179
-        case RNPTypeEvent:
180
-            return [RNPEvent request:@"event" completionHandler:resolve];
181
-        case RNPTypeReminder:
182
-            return [RNPEvent request:@"reminder" completionHandler:resolve];
183
-        case RNPTypeBluetooth:
184
-            return [self requestBluetooth:resolve];
185
-        case RNPTypeNotification:
186
-            return [self requestNotification:json resolve:resolve];
187
-        case RNPTypeSpeechRecognition:
188
-            return [RNPSpeechRecognition request:resolve];
189
-        case RNPTypeMediaLibrary:
190
-            return [RNPMediaLibrary request:resolve];
191
-        case RNPTypeMotion:
192
-            return [RNPMotion request:resolve];
193
-        default:
194
-            break;
195
-    }
196
-
197
-
198
-}
199
-
200
-- (void) requestLocation:(id)json resolve:(RCTPromiseResolveBlock)resolve
201
-{
202
-    if (self.locationMgr == nil) {
203
-        self.locationMgr = [[RNPLocation alloc] init];
204
-    }
205
-
206
-    NSString *type = [RCTConvert NSString:json];
207
-
208
-    [self.locationMgr request:type completionHandler:resolve];
209
-}
210
-
211
-- (void) requestNotification:(id)json resolve:(RCTPromiseResolveBlock)resolve
212
-{
213
-    NSArray *typeStrings = [RCTConvert NSArray:json];
214
-
215
-    UIUserNotificationType types;
216
-    if ([typeStrings containsObject:@"alert"])
217
-        types = types | UIUserNotificationTypeAlert;
218
-
219
-    if ([typeStrings containsObject:@"badge"])
220
-        types = types | UIUserNotificationTypeBadge;
221
-
222
-    if ([typeStrings containsObject:@"sound"])
223
-        types = types | UIUserNotificationTypeSound;
224
-
225
-
226
-    if (self.notificationMgr == nil) {
227
-        self.notificationMgr = [[RNPNotification alloc] init];
228
-    }
229
-
230
-    [self.notificationMgr request:types completionHandler:resolve];
231
-
232
-}
233
-
234
-
235
-- (void) requestBluetooth:(RCTPromiseResolveBlock)resolve
236
-{
237
-    if (self.bluetoothMgr == nil) {
238
-        self.bluetoothMgr = [[RNPBluetooth alloc] init];
239
-    }
240
-
241
-    [self.bluetoothMgr request:resolve];
242
-}
243
-
244
-
245
-
246
-
247
-@end

+ 0
- 348
ios/ReactNativePermissions.xcodeproj/project.pbxproj 查看文件

@@ -1,348 +0,0 @@
1
-// !$*UTF8*$!
2
-{
3
-	archiveVersion = 1;
4
-	classes = {
5
-	};
6
-	objectVersion = 46;
7
-	objects = {
8
-
9
-/* Begin PBXBuildFile section */
10
-		488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = 488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */; };
11
-		488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */; };
12
-		669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */; };
13
-		669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F51FE4416B008596CD /* ReactNativePermissions.m */; };
14
-		6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */; };
15
-		6695820E1FE441A8008596CD /* RNPLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FE1FE441A7008596CD /* RNPLocation.m */; };
16
-		6695820F1FE441A8008596CD /* RNPBluetooth.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FF1FE441A7008596CD /* RNPBluetooth.m */; };
17
-		669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582001FE441A7008596CD /* RNPBackgroundRefresh.m */; };
18
-		669582111FE441A8008596CD /* RNPNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582011FE441A7008596CD /* RNPNotification.m */; };
19
-		669582121FE441A8008596CD /* RNPPhoto.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582031FE441A7008596CD /* RNPPhoto.m */; };
20
-		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
21
-		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
22
-		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
23
-		D0AD62322000657000D89898 /* RNPMotion.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AD62312000657000D89898 /* RNPMotion.m */; };
24
-/* End PBXBuildFile section */
25
-
26
-/* Begin PBXCopyFilesBuildPhase section */
27
-		9D23B34D1C767B80008B4819 /* CopyFiles */ = {
28
-			isa = PBXCopyFilesBuildPhase;
29
-			buildActionMask = 2147483647;
30
-			dstPath = "include/$(PRODUCT_NAME)";
31
-			dstSubfolderSpec = 16;
32
-			files = (
33
-			);
34
-			runOnlyForDeploymentPostprocessing = 0;
35
-		};
36
-/* End PBXCopyFilesBuildPhase section */
37
-
38
-/* Begin PBXFileReference section */
39
-		488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNPMediaLibrary.m; sourceTree = "<group>"; };
40
-		488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNPMediaLibrary.h; sourceTree = "<group>"; };
41
-		488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
42
-		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
43
-		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
44
-		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
45
-		669581F61FE4416B008596CD /* RCTConvert+RNPStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+RNPStatus.h"; sourceTree = "<group>"; };
46
-		669581FB1FE441A7008596CD /* RNPContacts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPContacts.h; sourceTree = "<group>"; };
47
-		669581FC1FE441A7008596CD /* RNPPhoto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPPhoto.h; sourceTree = "<group>"; };
48
-		669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPSpeechRecognition.m; sourceTree = "<group>"; };
49
-		669581FE1FE441A7008596CD /* RNPLocation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPLocation.m; sourceTree = "<group>"; };
50
-		669581FF1FE441A7008596CD /* RNPBluetooth.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPBluetooth.m; sourceTree = "<group>"; };
51
-		669582001FE441A7008596CD /* RNPBackgroundRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPBackgroundRefresh.m; sourceTree = "<group>"; };
52
-		669582011FE441A7008596CD /* RNPNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPNotification.m; sourceTree = "<group>"; };
53
-		669582021FE441A7008596CD /* RNPLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPLocation.h; sourceTree = "<group>"; };
54
-		669582031FE441A7008596CD /* RNPPhoto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPPhoto.m; sourceTree = "<group>"; };
55
-		669582041FE441A7008596CD /* RNPAudioVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPAudioVideo.h; sourceTree = "<group>"; };
56
-		669582051FE441A7008596CD /* RNPBackgroundRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPBackgroundRefresh.h; sourceTree = "<group>"; };
57
-		669582061FE441A7008596CD /* RNPEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPEvent.h; sourceTree = "<group>"; };
58
-		669582071FE441A7008596CD /* RNPAudioVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPAudioVideo.m; sourceTree = "<group>"; };
59
-		669582081FE441A8008596CD /* RNPContacts.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPContacts.m; sourceTree = "<group>"; };
60
-		669582091FE441A8008596CD /* RNPBluetooth.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPBluetooth.h; sourceTree = "<group>"; };
61
-		6695820A1FE441A8008596CD /* RNPEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPEvent.m; sourceTree = "<group>"; };
62
-		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
63
-		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
64
-		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
65
-		D0AD62302000656F00D89898 /* RNPMotion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPMotion.h; sourceTree = "<group>"; };
66
-		D0AD62312000657000D89898 /* RNPMotion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPMotion.m; sourceTree = "<group>"; };
67
-/* End PBXFileReference section */
68
-
69
-/* Begin PBXFrameworksBuildPhase section */
70
-		9D23B34C1C767B80008B4819 /* Frameworks */ = {
71
-			isa = PBXFrameworksBuildPhase;
72
-			buildActionMask = 2147483647;
73
-			files = (
74
-				488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */,
75
-			);
76
-			runOnlyForDeploymentPostprocessing = 0;
77
-		};
78
-/* End PBXFrameworksBuildPhase section */
79
-
80
-/* Begin PBXGroup section */
81
-		488FE2A0200BCEC900E05AB0 /* Frameworks */ = {
82
-			isa = PBXGroup;
83
-			children = (
84
-				488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */,
85
-			);
86
-			name = Frameworks;
87
-			sourceTree = "<group>";
88
-		};
89
-		669581FA1FE44191008596CD /* Permissions */ = {
90
-			isa = PBXGroup;
91
-			children = (
92
-				669582041FE441A7008596CD /* RNPAudioVideo.h */,
93
-				669582071FE441A7008596CD /* RNPAudioVideo.m */,
94
-				669582051FE441A7008596CD /* RNPBackgroundRefresh.h */,
95
-				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
96
-				669582091FE441A8008596CD /* RNPBluetooth.h */,
97
-				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
98
-				488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */,
99
-				488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */,
100
-				669581FB1FE441A7008596CD /* RNPContacts.h */,
101
-				669582081FE441A8008596CD /* RNPContacts.m */,
102
-				669582061FE441A7008596CD /* RNPEvent.h */,
103
-				6695820A1FE441A8008596CD /* RNPEvent.m */,
104
-				D0AD62302000656F00D89898 /* RNPMotion.h */,
105
-				D0AD62312000657000D89898 /* RNPMotion.m */,
106
-				669582021FE441A7008596CD /* RNPLocation.h */,
107
-				669581FE1FE441A7008596CD /* RNPLocation.m */,
108
-				6695820C1FE441A8008596CD /* RNPNotification.h */,
109
-				669582011FE441A7008596CD /* RNPNotification.m */,
110
-				669581FC1FE441A7008596CD /* RNPPhoto.h */,
111
-				669582031FE441A7008596CD /* RNPPhoto.m */,
112
-				6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */,
113
-				669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */,
114
-			);
115
-			path = Permissions;
116
-			sourceTree = "<group>";
117
-		};
118
-		9D23B3461C767B80008B4819 = {
119
-			isa = PBXGroup;
120
-			children = (
121
-				669581FA1FE44191008596CD /* Permissions */,
122
-				669581F61FE4416B008596CD /* RCTConvert+RNPStatus.h */,
123
-				669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */,
124
-				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
125
-				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
126
-				9D23B3501C767B80008B4819 /* Products */,
127
-				488FE2A0200BCEC900E05AB0 /* Frameworks */,
128
-			);
129
-			sourceTree = "<group>";
130
-		};
131
-		9D23B3501C767B80008B4819 /* Products */ = {
132
-			isa = PBXGroup;
133
-			children = (
134
-				9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */,
135
-			);
136
-			name = Products;
137
-			sourceTree = "<group>";
138
-		};
139
-/* End PBXGroup section */
140
-
141
-/* Begin PBXNativeTarget section */
142
-		9D23B34E1C767B80008B4819 /* ReactNativePermissions */ = {
143
-			isa = PBXNativeTarget;
144
-			buildConfigurationList = 9D23B3581C767B80008B4819 /* Build configuration list for PBXNativeTarget "ReactNativePermissions" */;
145
-			buildPhases = (
146
-				9D23B34B1C767B80008B4819 /* Sources */,
147
-				9D23B34C1C767B80008B4819 /* Frameworks */,
148
-				9D23B34D1C767B80008B4819 /* CopyFiles */,
149
-			);
150
-			buildRules = (
151
-			);
152
-			dependencies = (
153
-			);
154
-			name = ReactNativePermissions;
155
-			productName = ReactNativePermissions;
156
-			productReference = 9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */;
157
-			productType = "com.apple.product-type.library.static";
158
-		};
159
-/* End PBXNativeTarget section */
160
-
161
-/* Begin PBXProject section */
162
-		9D23B3471C767B80008B4819 /* Project object */ = {
163
-			isa = PBXProject;
164
-			attributes = {
165
-				LastUpgradeCheck = 0820;
166
-				ORGANIZATIONNAME = "Yonah Forst";
167
-				TargetAttributes = {
168
-					9D23B34E1C767B80008B4819 = {
169
-						CreatedOnToolsVersion = 7.1;
170
-					};
171
-				};
172
-			};
173
-			buildConfigurationList = 9D23B34A1C767B80008B4819 /* Build configuration list for PBXProject "ReactNativePermissions" */;
174
-			compatibilityVersion = "Xcode 3.2";
175
-			developmentRegion = English;
176
-			hasScannedForEncodings = 0;
177
-			knownRegions = (
178
-				en,
179
-			);
180
-			mainGroup = 9D23B3461C767B80008B4819;
181
-			productRefGroup = 9D23B3501C767B80008B4819 /* Products */;
182
-			projectDirPath = "";
183
-			projectRoot = "";
184
-			targets = (
185
-				9D23B34E1C767B80008B4819 /* ReactNativePermissions */,
186
-			);
187
-		};
188
-/* End PBXProject section */
189
-
190
-/* Begin PBXSourcesBuildPhase section */
191
-		9D23B34B1C767B80008B4819 /* Sources */ = {
192
-			isa = PBXSourcesBuildPhase;
193
-			buildActionMask = 2147483647;
194
-			files = (
195
-				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
196
-				488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */,
197
-				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
198
-				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
199
-				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,
200
-				6695820E1FE441A8008596CD /* RNPLocation.m in Sources */,
201
-				6695820F1FE441A8008596CD /* RNPBluetooth.m in Sources */,
202
-				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
203
-				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
204
-				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
205
-				D0AD62322000657000D89898 /* RNPMotion.m in Sources */,
206
-				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
207
-				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
208
-			);
209
-			runOnlyForDeploymentPostprocessing = 0;
210
-		};
211
-/* End PBXSourcesBuildPhase section */
212
-
213
-/* Begin XCBuildConfiguration section */
214
-		9D23B3561C767B80008B4819 /* Debug */ = {
215
-			isa = XCBuildConfiguration;
216
-			buildSettings = {
217
-				ALWAYS_SEARCH_USER_PATHS = NO;
218
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
219
-				CLANG_CXX_LIBRARY = "libc++";
220
-				CLANG_ENABLE_MODULES = YES;
221
-				CLANG_ENABLE_OBJC_ARC = YES;
222
-				CLANG_WARN_BOOL_CONVERSION = YES;
223
-				CLANG_WARN_CONSTANT_CONVERSION = YES;
224
-				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
225
-				CLANG_WARN_EMPTY_BODY = YES;
226
-				CLANG_WARN_ENUM_CONVERSION = YES;
227
-				CLANG_WARN_INT_CONVERSION = YES;
228
-				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
229
-				CLANG_WARN_UNREACHABLE_CODE = YES;
230
-				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
231
-				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
232
-				COPY_PHASE_STRIP = NO;
233
-				DEBUG_INFORMATION_FORMAT = dwarf;
234
-				ENABLE_STRICT_OBJC_MSGSEND = YES;
235
-				ENABLE_TESTABILITY = YES;
236
-				GCC_C_LANGUAGE_STANDARD = gnu99;
237
-				GCC_DYNAMIC_NO_PIC = NO;
238
-				GCC_NO_COMMON_BLOCKS = YES;
239
-				GCC_OPTIMIZATION_LEVEL = 0;
240
-				GCC_PREPROCESSOR_DEFINITIONS = (
241
-					"DEBUG=1",
242
-					"$(inherited)",
243
-				);
244
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
245
-				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
246
-				GCC_WARN_UNDECLARED_SELECTOR = YES;
247
-				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
248
-				GCC_WARN_UNUSED_FUNCTION = YES;
249
-				GCC_WARN_UNUSED_VARIABLE = YES;
250
-				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
251
-				MTL_ENABLE_DEBUG_INFO = YES;
252
-				ONLY_ACTIVE_ARCH = YES;
253
-				SDKROOT = iphoneos;
254
-			};
255
-			name = Debug;
256
-		};
257
-		9D23B3571C767B80008B4819 /* Release */ = {
258
-			isa = XCBuildConfiguration;
259
-			buildSettings = {
260
-				ALWAYS_SEARCH_USER_PATHS = NO;
261
-				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
262
-				CLANG_CXX_LIBRARY = "libc++";
263
-				CLANG_ENABLE_MODULES = YES;
264
-				CLANG_ENABLE_OBJC_ARC = YES;
265
-				CLANG_WARN_BOOL_CONVERSION = YES;
266
-				CLANG_WARN_CONSTANT_CONVERSION = YES;
267
-				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
268
-				CLANG_WARN_EMPTY_BODY = YES;
269
-				CLANG_WARN_ENUM_CONVERSION = YES;
270
-				CLANG_WARN_INT_CONVERSION = YES;
271
-				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
272
-				CLANG_WARN_UNREACHABLE_CODE = YES;
273
-				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
274
-				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
275
-				COPY_PHASE_STRIP = NO;
276
-				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
277
-				ENABLE_NS_ASSERTIONS = NO;
278
-				ENABLE_STRICT_OBJC_MSGSEND = YES;
279
-				GCC_C_LANGUAGE_STANDARD = gnu99;
280
-				GCC_NO_COMMON_BLOCKS = YES;
281
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
282
-				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
283
-				GCC_WARN_UNDECLARED_SELECTOR = YES;
284
-				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
285
-				GCC_WARN_UNUSED_FUNCTION = YES;
286
-				GCC_WARN_UNUSED_VARIABLE = YES;
287
-				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
288
-				MTL_ENABLE_DEBUG_INFO = NO;
289
-				SDKROOT = iphoneos;
290
-				VALIDATE_PRODUCT = YES;
291
-			};
292
-			name = Release;
293
-		};
294
-		9D23B3591C767B80008B4819 /* Debug */ = {
295
-			isa = XCBuildConfiguration;
296
-			buildSettings = {
297
-				HEADER_SEARCH_PATHS = (
298
-					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
299
-					"$(SRCROOT)/../../React/**",
300
-					"$(SRCROOT)/node_modules/react-native/React/**",
301
-					"$(SRCROOT)/../react-native/React/**",
302
-				);
303
-				OTHER_LDFLAGS = "-ObjC";
304
-				PRODUCT_NAME = "$(TARGET_NAME)";
305
-				SKIP_INSTALL = YES;
306
-			};
307
-			name = Debug;
308
-		};
309
-		9D23B35A1C767B80008B4819 /* Release */ = {
310
-			isa = XCBuildConfiguration;
311
-			buildSettings = {
312
-				HEADER_SEARCH_PATHS = (
313
-					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
314
-					"$(SRCROOT)/../../React/**",
315
-					"$(SRCROOT)/node_modules/react-native/React/**",
316
-					"$(SRCROOT)/../react-native/React/**",
317
-				);
318
-				OTHER_LDFLAGS = "-ObjC";
319
-				PRODUCT_NAME = "$(TARGET_NAME)";
320
-				SKIP_INSTALL = YES;
321
-			};
322
-			name = Release;
323
-		};
324
-/* End XCBuildConfiguration section */
325
-
326
-/* Begin XCConfigurationList section */
327
-		9D23B34A1C767B80008B4819 /* Build configuration list for PBXProject "ReactNativePermissions" */ = {
328
-			isa = XCConfigurationList;
329
-			buildConfigurations = (
330
-				9D23B3561C767B80008B4819 /* Debug */,
331
-				9D23B3571C767B80008B4819 /* Release */,
332
-			);
333
-			defaultConfigurationIsVisible = 0;
334
-			defaultConfigurationName = Release;
335
-		};
336
-		9D23B3581C767B80008B4819 /* Build configuration list for PBXNativeTarget "ReactNativePermissions" */ = {
337
-			isa = XCConfigurationList;
338
-			buildConfigurations = (
339
-				9D23B3591C767B80008B4819 /* Debug */,
340
-				9D23B35A1C767B80008B4819 /* Release */,
341
-			);
342
-			defaultConfigurationIsVisible = 0;
343
-			defaultConfigurationName = Release;
344
-		};
345
-/* End XCConfigurationList section */
346
-	};
347
-	rootObject = 9D23B3471C767B80008B4819 /* Project object */;
348
-}

+ 0
- 113
lib/permissions.android.js 查看文件

@@ -1,113 +0,0 @@
1
-// @flow
2
-
3
-import { AsyncStorage, NativeModules, PermissionsAndroid } from "react-native";
4
-
5
-type Status = "authorized" | "denied" | "restricted" | "undetermined";
6
-type Rationale = { title: string, message: string };
7
-type CheckOptions = string | { type: string };
8
-type RequestOptions = string | { type: string, rationale?: Rationale };
9
-
10
-const permissionTypes = {
11
-  location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
12
-  camera: PermissionsAndroid.PERMISSIONS.CAMERA,
13
-  microphone: PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
14
-  contacts: PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
15
-  event: PermissionsAndroid.PERMISSIONS.READ_CALENDAR,
16
-  storage: PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
17
-  photo: PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
18
-  callPhone: PermissionsAndroid.PERMISSIONS.CALL_PHONE,
19
-  readSms: PermissionsAndroid.PERMISSIONS.READ_SMS,
20
-  receiveSms: PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
21
-};
22
-
23
-const RESULTS = {
24
-  [PermissionsAndroid.RESULTS.GRANTED]: "authorized",
25
-  [PermissionsAndroid.RESULTS.DENIED]: "denied",
26
-  [PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN]: "restricted",
27
-};
28
-
29
-const STORAGE_KEY = "@RNPermissions:didAskPermission:";
30
-
31
-const setDidAskOnce = (permission: string) =>
32
-  AsyncStorage.setItem(STORAGE_KEY + permission, "true");
33
-
34
-const getDidAskOnce = (permission: string) =>
35
-  AsyncStorage.getItem(STORAGE_KEY + permission).then(item => !!item);
36
-
37
-class ReactNativePermissions {
38
-  canOpenSettings: () => Promise<boolean> = () => Promise.resolve(false);
39
-
40
-  openSettings: () => Promise<*> = () =>
41
-    Promise.reject(new Error("'openSettings' is deprecated on android"));
42
-
43
-  getTypes: () => Array<string> = () => Object.keys(permissionTypes);
44
-
45
-  check = (permission: string, options?: CheckOptions): Promise<Status> => {
46
-    if (!permissionTypes[permission]) {
47
-      const error = new Error(
48
-        `ReactNativePermissions: ${permission} is not a valid permission type on Android`,
49
-      );
50
-
51
-      return Promise.reject(error);
52
-    }
53
-
54
-    return PermissionsAndroid.check(permissionTypes[permission]).then(
55
-      isAuthorized => {
56
-        if (isAuthorized) {
57
-          return "authorized";
58
-        }
59
-
60
-        return getDidAskOnce(permission).then(didAsk => {
61
-          if (didAsk) {
62
-            return NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(
63
-              permissionTypes[permission],
64
-            ).then(shouldShow => (shouldShow ? "denied" : "restricted"));
65
-          }
66
-
67
-          return "undetermined";
68
-        });
69
-      },
70
-    );
71
-  };
72
-
73
-  request = (permission: string, options?: RequestOptions): Promise<Status> => {
74
-    if (!permissionTypes[permission]) {
75
-      const error = new Error(
76
-        `ReactNativePermissions: ${permission} is not a valid permission type on Android`,
77
-      );
78
-
79
-      return Promise.reject(error);
80
-    }
81
-
82
-    let rationale;
83
-
84
-    if (options && options.rationale) {
85
-      rationale = options.rationale;
86
-    }
87
-
88
-    return PermissionsAndroid.request(
89
-      permissionTypes[permission],
90
-      rationale,
91
-    ).then(result => {
92
-      // PermissionsAndroid.request() to native module resolves to boolean
93
-      // rather than string if running on OS version prior to Android M
94
-      if (typeof result === "boolean") {
95
-        return result ? "authorized" : "denied";
96
-      }
97
-
98
-      return setDidAskOnce(permission).then(() => RESULTS[result]);
99
-    });
100
-  };
101
-
102
-  checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
103
-    Promise.all(permissions.map(permission => this.check(permission))).then(
104
-      result =>
105
-        result.reduce((acc, value, index) => {
106
-          const name = permissions[index];
107
-          acc[name] = value;
108
-          return acc;
109
-        }, {}),
110
-    );
111
-}
112
-
113
-export default new ReactNativePermissions();

+ 0
- 105
lib/permissions.ios.js 查看文件

@@ -1,105 +0,0 @@
1
-// @flow
2
-
3
-import { NativeModules } from "react-native";
4
-const PermissionsIOS = NativeModules.ReactNativePermissions;
5
-
6
-type Status = "authorized" | "denied" | "restricted" | "undetermined";
7
-type Rationale = { title: string, message: string };
8
-type CheckOptions = string | { type: string };
9
-type RequestOptions = string | { type: string, rationale?: Rationale };
10
-
11
-const permissionTypes = [
12
-  "location",
13
-  "camera",
14
-  "microphone",
15
-  "photo",
16
-  "contacts",
17
-  "event",
18
-  "reminder",
19
-  "bluetooth",
20
-  "notification",
21
-  "backgroundRefresh",
22
-  "speechRecognition",
23
-  "mediaLibrary",
24
-  "motion",
25
-];
26
-
27
-const DEFAULTS = {
28
-  location: "whenInUse",
29
-  notification: ["alert", "badge", "sound"],
30
-};
31
-
32
-class ReactNativePermissions {
33
-  canOpenSettings: () => Promise<boolean> = () =>
34
-    PermissionsIOS.canOpenSettings();
35
-
36
-  openSettings: () => Promise<*> = () => PermissionsIOS.openSettings();
37
-
38
-  getTypes: () => Array<string> = () => permissionTypes;
39
-
40
-  check = (permission: string, options?: CheckOptions): Promise<Status> => {
41
-    if (!permissionTypes.includes(permission)) {
42
-      const error = new Error(
43
-        `ReactNativePermissions: ${permission} is not a valid permission type on iOS`,
44
-      );
45
-
46
-      return Promise.reject(error);
47
-    }
48
-
49
-    let type;
50
-
51
-    if (typeof options === "string") {
52
-      type = options;
53
-    } else if (options && options.type) {
54
-      type = options.type;
55
-    }
56
-
57
-    return PermissionsIOS.getPermissionStatus(
58
-      permission,
59
-      type || DEFAULTS[permission],
60
-    );
61
-  };
62
-
63
-  request = (permission: string, options?: RequestOptions): Promise<Status> => {
64
-    if (!permissionTypes.includes(permission)) {
65
-      const error = new Error(
66
-        `ReactNativePermissions: ${permission} is not a valid permission type on iOS`,
67
-      );
68
-
69
-      return Promise.reject(error);
70
-    }
71
-
72
-    if (permission == "backgroundRefresh") {
73
-      const error = new Error(
74
-        "ReactNativePermissions: You cannot request backgroundRefresh",
75
-      );
76
-
77
-      return Promise.reject(error);
78
-    }
79
-
80
-    let type;
81
-
82
-    if (typeof options === "string") {
83
-      type = options;
84
-    } else if (options && options.type) {
85
-      type = options.type;
86
-    }
87
-
88
-    return PermissionsIOS.requestPermission(
89
-      permission,
90
-      type || DEFAULTS[permission],
91
-    );
92
-  };
93
-
94
-  checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
95
-    Promise.all(permissions.map(permission => this.check(permission))).then(
96
-      result =>
97
-        result.reduce((acc, value, index) => {
98
-          const name = permissions[index];
99
-          acc[name] = value;
100
-          return acc;
101
-        }, {}),
102
-    );
103
-}
104
-
105
-export default new ReactNativePermissions();

+ 9
- 8
package.json 查看文件

@@ -1,20 +1,20 @@
1 1
 {
2 2
   "name": "react-native-permissions",
3 3
   "version": "2.0.0-alpha.1",
4
+  "license": "MIT",
4 5
   "description": "Check and request user permissions in React Native.",
5 6
   "author": "Yonah Forst <yonaforst@hotmail.com>",
7
+  "main": "index.js",
6 8
   "homepage": "https://github.com/yonahforst/react-native-permissions",
9
+  "repository": {
10
+    "type": "git",
11
+    "url": "https://github.com/yonahforst/react-native-permissions.git"
12
+  },
7 13
   "keywords": [
8 14
     "react-native",
9 15
     "react-permissions",
10 16
     "permissions"
11 17
   ],
12
-  "main": "index.js",
13
-  "license": "MIT",
14
-  "repository": {
15
-    "type": "git",
16
-    "url": "https://github.com/yonahforst/react-native-permissions.git"
17
-  },
18 18
   "scripts": {
19 19
     "precommit": "lint-staged",
20 20
     "format": "prettier --write '**/*.{js,json,md}'",
@@ -27,10 +27,11 @@
27 27
     ]
28 28
   },
29 29
   "peerDependencies": {
30
-    "react-native": ">=0.56.0"
30
+    "react": ">=16.6.3",
31
+    "react-native": ">=0.58.3"
31 32
   },
32 33
   "devDependencies": {
33
-    "flow-bin": "0.91.0",
34
+    "flow-bin": "0.86.0",
34 35
     "husky": "1.3.1",
35 36
     "lint-staged": "8.1.1",
36 37
     "prettier": "1.16.1"

+ 4
- 4
yarn.lock 查看文件

@@ -502,10 +502,10 @@ find-up@^3.0.0:
502 502
   dependencies:
503 503
     locate-path "^3.0.0"
504 504
 
505
-flow-bin@0.91.0:
506
-  version "0.91.0"
507
-  resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.91.0.tgz#f5c89729f74b2ccbd47df6fbfadbdcc89cc1e478"
508
-  integrity sha512-j+L+xNiUYnZZ27MjVI0y2c9474ZHOvdSQq0Tjwh56mEA7tfxYqp5Dcb6aZSwvs3tGMTjCrZow9aUlZf3OoRyDQ==
505
+flow-bin@0.86.0:
506
+  version "0.86.0"
507
+  resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.86.0.tgz#153a28722b4dc13b7200c74b644dd4d9f4969a11"
508
+  integrity sha512-ulRvFH3ewGIYwg+qPk/OJXoe3Nhqi0RyR0wqgK0b1NzUDEC6O99zU39MBTickXvlrr6iwRO6Wm4lVGeDmnzbew==
509 509
 
510 510
 fn-name@~2.0.1:
511 511
   version "2.0.1"