Browse Source

Replaced expo permissions by react native one

Arnaud Vergnet 3 years ago
parent
commit
bb5d453a2b

+ 0
- 1
android/app/src/main/java/fr/amicaleinsat/application/generated/BasePackageList.java View File

@@ -16,7 +16,6 @@ public class BasePackageList {
16 16
         new expo.modules.imageloader.ImageLoaderPackage(),
17 17
         new expo.modules.keepawake.KeepAwakePackage(),
18 18
         new expo.modules.lineargradient.LinearGradientPackage(),
19
-        new expo.modules.localization.LocalizationPackage(),
20 19
         new expo.modules.location.LocationPackage(),
21 20
         new expo.modules.permissions.PermissionsPackage(),
22 21
         new expo.modules.securestore.SecureStorePackage(),

+ 1
- 1
package.json View File

@@ -27,7 +27,6 @@
27 27
     "expo": "^37.0.0",
28 28
     "expo-barcode-scanner": "~8.1.0",
29 29
     "expo-camera": "latest",
30
-    "expo-permissions": "~8.1.0",
31 30
     "expo-secure-store": "~8.1.0",
32 31
     "i18n-js": "^3.3.0",
33 32
     "react": "~16.9.0",
@@ -45,6 +44,7 @@
45 44
     "react-native-localize": "^1.4.0",
46 45
     "react-native-modalize": "^1.3.6",
47 46
     "react-native-paper": "^3.8.0",
47
+    "react-native-permissions": "^2.1.3",
48 48
     "react-native-reanimated": "~1.7.0",
49 49
     "react-native-render-html": "^4.1.2",
50 50
     "react-native-safe-area-context": "0.7.3",

+ 23
- 14
src/utils/Notifications.js View File

@@ -1,6 +1,6 @@
1 1
 // @flow
2 2
 
3
-import * as Permissions from 'expo-permissions';
3
+import {checkNotifications, requestNotifications, RESULTS} from 'react-native-permissions';
4 4
 import {Notifications} from 'expo';
5 5
 import AsyncStorageManager from "../managers/AsyncStorageManager";
6 6
 import LocaleManager from "../managers/LocaleManager";
@@ -14,13 +14,22 @@ const EXPO_TOKEN_SERVER = 'https://etud.insa-toulouse.fr/~amicale_app/expo_notif
14 14
  * @returns {Promise}
15 15
  */
16 16
 export async function askPermissions() {
17
-    const {status: existingStatus} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
18
-    let finalStatus = existingStatus;
19
-    if (existingStatus !== 'granted') {
20
-        const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
21
-        finalStatus = status;
22
-    }
23
-    return finalStatus === 'granted';
17
+    return new Promise(((resolve, reject) => {
18
+        checkNotifications().then(({status, settings}) => {
19
+            if (status === RESULTS.GRANTED)
20
+                resolve();
21
+            else if (status === RESULTS.BLOCKED)
22
+                reject()
23
+            else {
24
+                requestNotifications().then(({status, settings}) => {
25
+                    if (status === RESULTS.GRANTED)
26
+                        resolve();
27
+                    else
28
+                        reject();
29
+                });
30
+            }
31
+        });
32
+    }));
24 33
 }
25 34
 
26 35
 /**
@@ -33,12 +42,12 @@ export async function askPermissions() {
33 42
 export async function initExpoToken() {
34 43
     let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
35 44
     if (token === '') {
36
-        try {
37
-            await askPermissions();
38
-            let expoToken = await Notifications.getExpoPushTokenAsync();
39
-            // Save token for instant use later on
40
-            AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
41
-        } catch (e) {}
45
+        askPermissions().then(() => {
46
+            Notifications.getExpoPushTokenAsync().then((token) => {
47
+                // Save token for instant use later on
48
+                AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, token);
49
+            });
50
+        });
42 51
     }
43 52
 }
44 53
 

Loading…
Cancel
Save