Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startWatching = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION)
if (status !== 'granted') {
// TODO: show error message
}
await Location.watchPositionAsync({
accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000,
distanceInterval: 5
}, location => {
console.log('location', location)
})
}
async function requestPermissionAsync(permission: Permissions.PermissionType) {
// Image Picker doesn't need permissions in the web
if (Platform.OS === 'web') {
return true;
}
const { status } = await Permissions.askAsync(permission);
return status === 'granted';
}
registerForPushNotificationsAsync = async () => {
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
let token = await Notifications.getExpoPushTokenAsync();
this._onSetPushToken(token);
} else {
// alert('Must use physical device for Push Notifications');
}
await scheduleMoodReminders();
};
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
import { Audio } from 'expo-av';
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import { connect } from 'react-redux';
import Stories from './components/Stories/StoriesExperimental';
import MainNavigation from './navigation/MainNavigation';
import NavigationService from './navigation/NavigationService';
import Gate from './rematch/Gate';
import dispatch from './rematch/dispatch';
import * as Permissions from 'expo-permissions';
const Settings = {
permissions: [Permissions.CAMERA, Permissions.AUDIO_RECORDING],
};
// import Stories from './components/Stories/Stories';
export default class App extends React.Component {
componentDidMount() {
for (const permission of Settings.permissions) {
dispatch().permissions.getAsync({ permission });
}
}
render() {
return (
{
export async function askForNotificationsPermission() {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return null;
}
export async function requestAsync(permission, shouldRequest, redirectReason) {
let status;
if (shouldRequest) {
status = (await Permissions.askAsync(permission)).status;
} else {
status = (await Permissions.getAsync(permission)).status;
}
if (status === 'denied' || (status === 'undetermined' && shouldRequest)) {
// Prompt to open settings and change the permission manually.
// When the user changes the permissions the app will reset so we should
// just return false regardless at this point.
return new Promise(resolve => {
Alert.alert(
'Oh no!',
redirectReason,
[
{
text: 'Nevermind',
onPress: () => resolve(false),
style: 'cancel',
},
{
async componentDidMount() {
// get exisiting locaton permissions first
const { status: existingStatus } = await Permissions.getAsync(
Permissions.LOCATION
);
let finalStatus = existingStatus;
// ask again to grant locaton permissions (if not already allowed)
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
finalStatus = status;
}
// still not allowed to use location?
if (finalStatus !== 'granted') {
return;
}
const { coords } = await Location.getCurrentPositionAsync();
const cameraAccessAsync = async () => {
// get exisiting camera permissions first
const { status: existingStatus } = await Permissions.getAsync(
Permissions.CAMERA
);
let finalStatus = existingStatus;
// ask again to grant camera permissions (if not already allowed)
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
finalStatus = status;
}
return finalStatus === 'granted';
};
export async function askForNotificationsPermission() {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
// install, so this will only ask on iOS
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
// Stop here if the user did not grant permissions
if (finalStatus !== 'granted') {
return null;
}
// Get the token that uniquely identifies this device
let token = await Notifications.getExpoPushTokenAsync();
return token;
}
registerForPushNotificationsAsync = async () => {
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
let token = await Notifications.getExpoPushTokenAsync();
this._onSetPushToken(token);
} else {
// alert('Must use physical device for Push Notifications');
}
await scheduleMoodReminders();
};