How to use the expo.Permissions.askAsync function in expo

To help you get started, we’ve selected a few expo 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 watanabeyu / expo-firebase-instagram / src / navigation / RootNavigation.js View on Github external
getDeviceToken = async () => {
    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') {
      return;
    }

    const deviceToken = await Notifications.getExpoPushTokenAsync();
    if (deviceToken) {
      firebase.updateUserToken(deviceToken);
    }
  }
github nomadcoders / nomadgrapp / redux / modules / user.js View on Github external
return async (dispatch, getState) => {
    const { user: { token } } = getState();
    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 === "denied") {
      return;
    }

    let pushToken = await Notifications.getExpoPushTokenAsync();

    console.log(pushToken);

    return fetch(`${API_URL}/users/push/`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `JWT ${token}`
github hyakt / expo-multiple-media-imagepicker / example / App.js View on Github external
async componentDidMount () {
    Permissions.askAsync(Permissions.CAMERA_ROLL).then(d => console.log(d))
  }
github Tkd-Alex / Garcon-Restaurant-Manager / garcon-react-native / src / registerNotification.js View on Github external
export default (async function registerForPushNotificationsAsync(user, token) {

  let { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
  if (status !== 'granted') return;
  let tokenPush = await Notifications.getExpoPushTokenAsync();
  if(tokenPush == user.push_token) return;

  return fetch(PUSH_ENDPOINT, {
    method: 'PUT',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization': token //JWT Token
    },
    body: JSON.stringify({
      token: tokenPush
    }),
  });
});
github syousif94 / frugalmaps / frugalapp / src / Notifications.js View on Github external
"To enable notifications, tap Open Settings and then toggle the Notifications switch.",
      [
        { text: "Cancel", style: "cancel" },
        {
          text: "Open Settings",
          onPress: () => {
            Linking.openURL("app-settings:");
          }
        }
      ]
    );

    return askStatus;
  }

  const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

  return status;
}
github watanabeyu / expo-firebase-instagram / src / screens / UserScreen / index.js View on Github external
onUserPress = async () => {
    const { me, dispatch } = this.props;

    const permissions = Permissions.CAMERA_ROLL;
    const { status } = await Permissions.askAsync(permissions);

    if (status) {
      const photo = await ImagePicker.launchImageLibraryAsync({
        allowsEditing: true,
        aspect: [1, 1],
      });

      if (!photo.cancelled) {
        const response = await firebase.changeUserImg(photo);
        if (!response.error) {
          dispatch({
            type: 'ME_SET', payload: { ...me, img: photo.uri },
          });
        }
      }
    }
github watanabeyu / expo-firebase-instagram / src / screens / TakeScreen / index.js View on Github external
onTabPress = async (mode = 'photo', headerTitle = I18n.t('Take.tab2')) => {
    const { flashMode } = this.state;
    const { navigation } = this.props;

    if (mode !== 'library') {
      this.setState({
        mode,
        flashMode: (mode === 'photo') ? flashMode : Camera.Constants.FlashMode.off,
      });

      navigation.setParams({
        headerTitle,
      });
    } else {
      const permissions = Permissions.CAMERA_ROLL;
      const { status } = await Permissions.askAsync(permissions);

      if (status) {
        const photo = await ImagePicker.launchImageLibraryAsync({
          allowsEditing: true,
          aspect: [1, 1],
        });

        if (!photo.cancelled) {
          navigation.push('TakePublish', { mode: 'photo', photo });
        }
      }
    }
  }
github yhenni1989 / Plush / src / components / Feed.js View on Github external
askPermissionsAsync = async () => {
    await Permissions.askAsync(Permissions.CAMERA_ROLL)
  }