forked from vergnet/application-amicale
Replaced expo permissions by react native one
This commit is contained in:
parent
b784a5d164
commit
bb5d453a2b
3 changed files with 24 additions and 16 deletions
|
@ -16,7 +16,6 @@ public class BasePackageList {
|
|||
new expo.modules.imageloader.ImageLoaderPackage(),
|
||||
new expo.modules.keepawake.KeepAwakePackage(),
|
||||
new expo.modules.lineargradient.LinearGradientPackage(),
|
||||
new expo.modules.localization.LocalizationPackage(),
|
||||
new expo.modules.location.LocationPackage(),
|
||||
new expo.modules.permissions.PermissionsPackage(),
|
||||
new expo.modules.securestore.SecureStorePackage(),
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
"expo": "^37.0.0",
|
||||
"expo-barcode-scanner": "~8.1.0",
|
||||
"expo-camera": "latest",
|
||||
"expo-permissions": "~8.1.0",
|
||||
"expo-secure-store": "~8.1.0",
|
||||
"i18n-js": "^3.3.0",
|
||||
"react": "~16.9.0",
|
||||
|
@ -45,6 +44,7 @@
|
|||
"react-native-localize": "^1.4.0",
|
||||
"react-native-modalize": "^1.3.6",
|
||||
"react-native-paper": "^3.8.0",
|
||||
"react-native-permissions": "^2.1.3",
|
||||
"react-native-reanimated": "~1.7.0",
|
||||
"react-native-render-html": "^4.1.2",
|
||||
"react-native-safe-area-context": "0.7.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import * as Permissions from 'expo-permissions';
|
||||
import {checkNotifications, requestNotifications, RESULTS} from 'react-native-permissions';
|
||||
import {Notifications} from 'expo';
|
||||
import AsyncStorageManager from "../managers/AsyncStorageManager";
|
||||
import LocaleManager from "../managers/LocaleManager";
|
||||
|
@ -14,13 +14,22 @@ const EXPO_TOKEN_SERVER = 'https://etud.insa-toulouse.fr/~amicale_app/expo_notif
|
|||
* @returns {Promise}
|
||||
*/
|
||||
export async function askPermissions() {
|
||||
const {status: existingStatus} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
|
||||
let finalStatus = existingStatus;
|
||||
if (existingStatus !== 'granted') {
|
||||
const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
|
||||
finalStatus = status;
|
||||
}
|
||||
return finalStatus === 'granted';
|
||||
return new Promise(((resolve, reject) => {
|
||||
checkNotifications().then(({status, settings}) => {
|
||||
if (status === RESULTS.GRANTED)
|
||||
resolve();
|
||||
else if (status === RESULTS.BLOCKED)
|
||||
reject()
|
||||
else {
|
||||
requestNotifications().then(({status, settings}) => {
|
||||
if (status === RESULTS.GRANTED)
|
||||
resolve();
|
||||
else
|
||||
reject();
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,12 +42,12 @@ export async function askPermissions() {
|
|||
export async function initExpoToken() {
|
||||
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
||||
if (token === '') {
|
||||
try {
|
||||
await askPermissions();
|
||||
let expoToken = await Notifications.getExpoPushTokenAsync();
|
||||
// Save token for instant use later on
|
||||
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
|
||||
} catch (e) {}
|
||||
askPermissions().then(() => {
|
||||
Notifications.getExpoPushTokenAsync().then((token) => {
|
||||
// Save token for instant use later on
|
||||
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue