How to use expo-permissions - 10 common examples

To help you get started, we’ve selected a few expo-permissions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github developmentseed / observe / app / components / GPSTracker.js View on Github external
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)
    })
  }
github expo / expo / apps / native-component-list / src / screens / ImagePickerScreen.tsx View on Github external
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';
}
github catalinmiron / uzual-mobile / screens / habits / Habits.js View on Github external
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();
  };
github EvanBacon / Instagram / App.js View on Github external
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 (
      
        
          
            
               {
github Vivify-Ideas / expo-boilerplate / services / PermissionsService.js View on Github external
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;
  }
github expo / expo / home / utils / PermissionUtils.js View on Github external
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',
          },
          {
github calebnance / expo-uber / src / screens / Home.js View on Github external
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();
github calebnance / expo-uber / src / constants / functions.js View on Github external
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';
};
github Vivify-Ideas / expo-boilerplate / services / PermissionsService.js View on Github external
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;
}
github catalinmiron / uzual-mobile / screens / habits / Habits.js View on Github external
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();
  };