How to use the expo-permissions.NOTIFICATIONS 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;
  }

  // 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();
  };
github expo / expo / home / utils / PermissionUtils.js View on Github external
import Constants from 'expo-constants';
import * as IntentLauncher from 'expo-intent-launcher';
import * as Permissions from 'expo-permissions';
import { Alert, Linking, Platform } from 'react-native';

const PermissionName = {
  [Permissions.CAMERA]: 'The Camera',
  [Permissions.LOCATION]: 'GPS',
  [Permissions.CAMERA_ROLL]: 'The Gallery',
  [Permissions.AUDIO_RECORDING]: 'The Microphone',
  [Permissions.NOTIFICATIONS]: 'Push Notifications',
  [Permissions.USER_FACING_NOTIFICATIONS]: 'Notifications',
  [Permissions.CONTACTS]: 'Your Contacts',
  [Permissions.CALENDAR]: 'Calendar',
  [Permissions.REMINDERS]: 'Reminders',
};

// Use a controlled prompt to ensure you retain access to the permission prompt.
// If the user rejects the controlled prompt, you can always prompt them again when they're ready.
// Otherwise you'll need to redirect the user to the system settings.
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;
  }
github molenzwiebel / Mimic / frontend / components / NotificationPrompt.tsx View on Github external
const onAccept = async () => {
        setProcessing(true);
        await Permissions.askAsync(Permissions.NOTIFICATIONS);
        await withComputerConfig(x => {
            x.hasPromptedForNotifications = true;
            x.readyCheckNotificationsEnabled = true;
            x.gameStartNotificationsEnabled = true;
        });
        await updateNotificationSubscriptions();
        setProcessing(false);
        onClose();
    };
github just1and0 / expo-push-notification-helper / Helpers / notifyinit.js View on Github external
initnotify: async ()=>{
           const {status} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
           if (status != "granted") {
                 alert('you need to enable notification permission in settings')
                 return false;
           } else {
               Notifications.createChannelAndroidAsync('default', {
                name: 'Default',
                sound: true,
                });
                 Notifications.createChannelAndroidAsync('reminders', {
                  name: 'Reminders',
                  priority: 'max',
                  vibrate: [0, 250, 250, 250],
                  sound: true,
                });
                 Notifications.createChannelAndroidAsync('chat-messages', {
                  name: 'Chat messages',
github Vivify-Ideas / expo-boilerplate / screens / NetworkInterceptor.js View on Github external
useEffect(async () => {
    await Permissions.askAsync(Permissions.NOTIFICATIONS);
    connectionInfo();
    setUrlEventListener();

    if (Platform.OS === OS_TYPES.ANDROID) {
      Notifications.createChannelAndroidAsync(DEFAULT, {
        name: NOTIFICATION,
        sound: true
      });
    }
    Notifications.addListener(handleNotification);
  }, []);
github expo / expo / apps / native-component-list / src / screens / NotificationScreen.tsx View on Github external
_obtainRemoteNotifPermissionsAsync = async () => {
    let permission = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    if (permission.status !== 'granted') {
      permission = await Permissions.askAsync(Permissions.NOTIFICATIONS);
      if (permission.status !== 'granted') {
        Alert.alert(
          `We don't have permission to receive remote notifications.`
        );
      }
    }
    return permission;
  }
github expo / expo / apps / storybook / stories / APIs / Permissions.stories.jsx View on Github external
onPress={() =>
                this.invokePermissionsFunction(
                  ...[
                    Permissions.CAMERA,
                    Permissions.AUDIO_RECORDING,
                    Permissions.LOCATION,
                    Permissions.USER_FACING_NOTIFICATIONS,
                    Permissions.NOTIFICATIONS,
                    Permissions.CONTACTS,
                    Permissions.SYSTEM_BRIGHTNESS,
                    Permissions.CAMERA_ROLL,
                    Permissions.CALENDAR,
                    Permissions.REMINDERS,
                  ]
                )
              }