How to use the expo-permissions.getAsync function in expo-permissions

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 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 expo / expo / apps / native-component-list / src / screens / NotificationScreen.tsx View on Github external
_obtainUserFacingNotifPermissionsAsync = async () => {
    let permission = await Permissions.getAsync(
      Permissions.USER_FACING_NOTIFICATIONS
    );
    if (permission.status !== 'granted') {
      permission = await Permissions.askAsync(
        Permissions.USER_FACING_NOTIFICATIONS
      );
      if (permission.status !== 'granted') {
        Alert.alert(`We don't have permission to present notifications.`);
      }
    }
    return permission;
  }
github molenzwiebel / Mimic / frontend / components / NotificationPrompt.tsx View on Github external
export async function shouldShowNotificationPrompt(): Promise {
    const settings = await withComputerConfig();
    const canPush = await Permissions.getAsync(Permissions.NOTIFICATIONS);

    return (
        !settings.hasPromptedForNotifications &&
        (canPush.status !== Permissions.PermissionStatus.DENIED || canPush.canAskAgain)
    );
}
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 {
github expo / expo / home / utils / PermissionUtils.js View on Github external
export async function controlledPromptAsync(permission, permissionReason, redirectReason) {
  const { status } = await Permissions.getAsync(permission);
  if (status === 'denied') {
    return requestAsync(permission, false, permissionReason || redirectReason);
  } else if (status === 'granted') {
    return true;
  }

  return new Promise(resolve => {
    Alert.alert(
      `Please Turn On ${PermissionName[permission]}`,
      permissionReason,
      [
        {
          text: 'Not Now',
          onPress: () => resolve(false),
        },
        {
github catalinmiron / uzual-mobile / screens / mood / Mood.js View on Github external
_onSaveMoodGraph = async () => {
    const { isLoading, imageUri } = this._getProps();
    const permission = await Permissions.getAsync(Permissions.CAMERA_ROLL);
    if (permission.status !== 'granted') {
      const newPermission = await Permissions.askAsync(Permissions.CAMERA_ROLL);
      if (newPermission.status === 'granted') {
        await CameraRoll.saveToCameraRoll(imageUri, 'photo');
      }
    } else {
      await CameraRoll.saveToCameraRoll(imageUri, 'photo');
    }

    this._cancelSharing();
  };