Replaced expo permissions by react native one

This commit is contained in:
Arnaud Vergnet 2020-04-27 22:05:36 +02:00
parent b784a5d164
commit bb5d453a2b
3 changed files with 24 additions and 16 deletions

View file

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

View file

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

View file

@ -1,6 +1,6 @@
// @flow // @flow
import * as Permissions from 'expo-permissions'; import {checkNotifications, requestNotifications, RESULTS} from 'react-native-permissions';
import {Notifications} from 'expo'; import {Notifications} from 'expo';
import AsyncStorageManager from "../managers/AsyncStorageManager"; import AsyncStorageManager from "../managers/AsyncStorageManager";
import LocaleManager from "../managers/LocaleManager"; import LocaleManager from "../managers/LocaleManager";
@ -14,13 +14,22 @@ const EXPO_TOKEN_SERVER = 'https://etud.insa-toulouse.fr/~amicale_app/expo_notif
* @returns {Promise} * @returns {Promise}
*/ */
export async function askPermissions() { export async function askPermissions() {
const {status: existingStatus} = await Permissions.getAsync(Permissions.NOTIFICATIONS); return new Promise(((resolve, reject) => {
let finalStatus = existingStatus; checkNotifications().then(({status, settings}) => {
if (existingStatus !== 'granted') { if (status === RESULTS.GRANTED)
const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS); resolve();
finalStatus = status; else if (status === RESULTS.BLOCKED)
reject()
else {
requestNotifications().then(({status, settings}) => {
if (status === RESULTS.GRANTED)
resolve();
else
reject();
});
} }
return finalStatus === 'granted'; });
}));
} }
/** /**
@ -33,12 +42,12 @@ export async function askPermissions() {
export async function initExpoToken() { export async function initExpoToken() {
let token = AsyncStorageManager.getInstance().preferences.expoToken.current; let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (token === '') { if (token === '') {
try { askPermissions().then(() => {
await askPermissions(); Notifications.getExpoPushTokenAsync().then((token) => {
let expoToken = await Notifications.getExpoPushTokenAsync();
// Save token for instant use later on // Save token for instant use later on
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken); AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, token);
} catch (e) {} });
});
} }
} }