Browse Source

updated readme

Yonah Forst 8 years ago
parent
commit
62ef70b38c
1 changed files with 46 additions and 81 deletions
  1. 46
    81
      README.md

+ 46
- 81
README.md View File

@@ -1,106 +1,71 @@
1
-# Discovery
2
-Discover nearby devices using BLE.
3
-
4
-React native implementation of https://github.com/omergul123/Discovery
5
-
6
-(Android uses https://github.com/joshblour/discovery-android)
1
+# React Native Permissions
2
+Check user permissions (iOS only)
7 3
 
8 4
 ##What
9
-Discovery is a very simple but useful library for discovering nearby devices with BLE(Bluetooth Low Energy) and for exchanging a value (kind of ID or username determined by you on the running app on peer device) regardless of whether the app on peer device works at foreground or background state.
5
+Some iOS features require the user grant permission before you can access them.
6
+
7
+This library lets you check the current status of those permissions. (Note: it _doesn't_ prompt the user, just silently checks the permission status)
10 8
 
9
+The current supported permissions are:
10
+- Location
11
+- Camera
12
+- Microhone
13
+- Photos
14
+- Contacts
15
+- Event
16
+- Bluetooth
17
+- RemoteNotifications (Push Notifications)
11 18
 
12 19
 ####Example
13 20
 ```java
14
-const {DeviceEventEmitter} = require('react-native');
15
-const Discovery = require('react-native-discovery');
16
-
17
-Discovery.initialize(
18
-  "3E1180E5-222E-43E9-98B4-E6C0DD18E728",
19
-  "SpacemanSpiff"
20
-);
21
-Discovery.setShouldAdvertise(true);
22
-Discovery.setShouldDiscover(true);
23
-
24
-// Listen for discovery changes
25
-DeviceEventEmitter.addListener(
26
-  'discoveredUsers',
27
-  (data) => {
28
-    if (data.didChange || data.usersChanged) //slight callback discrepancy between the iOS and Android libraries
29
-      console.log(data.users)
21
+const Permissions = require('react-native-permissions');
22
+
23
+//....
24
+  componentDidMount() {
25
+    Permissions.locationPermissionStatus()
26
+    .then(response => {
27
+      if (response == Permissions.StatusUndetermined) {
28
+        alert("Undetermined");
29
+      } else if (response == Permissions.StatusDenied) {
30
+        alert("Denied");
31
+      } else if (response == Permissions.StatusAuthorized) {
32
+        alert("Authorized");
33
+      } else if (response == Permissions.StatusRestricted) {
34
+        alert("Restricted");
35
+      }
36
+    });
30 37
   }
31
-);
32
-
38
+//...
33 39
 ```
34 40
 
35 41
 
36 42
 ####API
37 43
 
38
-`initialize(uuidString, username)` - Initialize the Discovery object with a UUID specific to your app, and a username specific to your device.
44
+As shown in the example, methods return a promise with the authorization status as an `int`. You can compare them to the following statuses: `StatusUndetermined`, `StatusDenied`, `StatusAuthorized`, `StatusRestricted`
45
+
46
+`locationPermissionStatus()` - checks for access to the user's current location. Note: `AuthorizedAlways` and `AuthorizedWhenInUse` both return `StatusAuthorized`
47
+
48
+`cameraPermissionStatus()` - checks for access to the phone's camera
39 49
 
40
-`setPaused(isPaused)` - bool. pauses advertising and detection
50
+`microphonePermissionStatus()` - checks for access to the phone's microphone
41 51
 
42
-`setShouldDiscover(shouldDiscover)` - bool. starts and stops discovery only
52
+`photoPermissionStatus()` - checks for access to the user's photo album
43 53
 
44
-`setShouldAdvertise(shouldAdvertise)` - bool. starts and stops advertising only
54
+`contactsPermissionStatus()` - checks for access to the user's address book
45 55
 
46
-`setUserTimeoutInterval(userTimeoutInterval)` - integer in seconds, default is 5. After not seeing a user for x seconds, we remove him from the users list in our callback.
47
-  
48
-  
49
-*The following two methods are specific to the Android version, since the Android docs advise against continuous scanning. Instead, we cycle scanning on and off. This also allows us to modify the scan behaviour when the app moves to the background.*
56
+`eventPermissionStatus(eventType)` - requires param `eventType`; either `reminder` or `event`. Checks for access to the users calendar events and reminders
50 57
 
51
-`setScanForSeconds(scanForSeconds)` - integer in seconds, default is 5. This parameter specifies the duration of the ON part of the scan cycle.
52
-    
53
-`setWaitForSeconds(waitForSeconds)` - integer in seconds default is 5. This parameter specifies the duration of the OFF part of the scan cycle.
58
+`bluetoothPermissionStatus()` - checks the authorization status of the `CBPeripheralManager` (for sharing data while backgrounded)
54 59
 
60
+`notificationPermissionStatus()` - checks if the user has authorized remote push notifications. Note: Apple only tells us if notifications are authorized or not, not the exact status. So this promise only returns `StatusUndetermined` or `StatusAuthorized`. You can determine if `StatusUndetermined` is actually `StatusRejected` by keeping track of whether or not you've already asked the user for permission.
55 61
 
56 62
 ##Setup
57 63
 
58 64
 ````
59
-npm install --save react-native-discovery
65
+npm install --save react-native-permissions
60 66
 ````
61 67
 
62 68
 ###iOS
63
-* Run open node_modules/react-native-discovery
64
-* Drag ReactNativeDiscovery.xcodeproj into your Libraries group
65
-
66
-###Android
67
-#####Step 1 - Update Gradle Settings
68
-
69
-```
70
-// file: android/settings.gradle
71
-...
72
-
73
-include ':react-native-discovery'
74
-project(':react-native-discovery').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-discovery/android')
75
-```
76
-#####Step 2 - Update Gradle Build
77
-
78
-```
79
-// file: android/app/build.gradle
80
-...
81
-
82
-dependencies {
83
-    ...
84
-    compile project(':react-native-discovery')
85
-}
86
-```
87
-#####Step 3 - Register React Package
88
-```
89
-...
90
-import com.joshblour.reactnativediscovery.ReactNativeDiscoveryPackage; // <--- import
91
-
92
-public class MainActivity extends ReactActivity {
93
-
94
-    ...
95
-
96
-    @Override
97
-    protected List<ReactPackage> getPackages() {
98
-        return Arrays.<ReactPackage>asList(
99
-            new MainReactPackage(),
100
-            new ReactNativeDiscoveryPackage(this) // <------ add the package
101
-        );
102
-    }
103
-
104
-    ...
105
-}
106
-```
69
+* Run open node_modules/react-native-permissions
70
+* Drag ReactNativePermissions.xcodeproj into the Libraries group of your app's Xcode project
71
+* Add libReactNativePermissions.a to `Build Phases -> Link Binary With Libraries.