How to use the expo.Permissions.NOTIFICATIONS 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 blockmason / lndr-mobile / legacy-src / utils / SetupPushNotifications.js View on Github external
export async function registerForPushNotificationsAsync () {
  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') {
    console.log('Failed to grant')
    return
  }

  // Get the token that uniquely identifies this device
  let token = await Notifications.getExpoPushTokenAsync()

  // POST the token to your backend server from where you can retrieve it to send push notifications.
  return fetch(PUSH_ENDPOINT, {
    method: 'POST',
    headers: {
github jnancy / Eventry / eventry-app / screens / LoginScreen.js View on Github external
async _registerForPushNotificationsAsync() {
      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;
      }
    
      // Get the token that uniquely identifies this device
      let token = await Notifications.getExpoPushTokenAsync();
      console.log("The auth key here " + this.state.Authkey);
      // POST the token to your backend server from where you can retrieve it to send push notifications.
      return fetch('http://eventry-dev.us-west-2.elasticbeanstalk.com/users/update_expo_token', {
        method: 'POST',
        headers: {
          'Authorization': "Token " + this.state.Authkey,
github EvanBacon / expo-firebase-tutorial / App.js View on Github external
async componentDidMount() {
    firebase.auth().onAuthStateChanged(auth => {
      if (!auth) {
        firebase.auth().signInAnonymously();
      }
      this.setState({ isSignedIn: !!auth });
    });



    //// WHATS AFTER THIS ........



    const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
    if (status !== 'granted') return;

    this.unsubscribe = firebase.messaging().onMessage(message => {
      console.log(message);
      alert('hey message');
    });

    const token = await firebase.iid().getToken();
    console.log({ token });
  }
github EvanBacon / pro-chat / client / src / constants / Settings.js View on Github external
users: 'users',
    complaints: 'complaints',
  },
  isDetached: false,
  googleLoginProps,
  facebookFields: fields,
  facebookLoginProps: {
    permissions: [
      'public_profile',
      'email',
      // 'user_friends'
    ],
  },
  permissions: [
    Permissions.LOCATION,
    Permissions.NOTIFICATIONS,
    Permissions.CONTACTS,
  ],
  hideBooty: true,
  noName: 'Sasuke Uchiha',
  isIos: Platform.OS === 'ios',
  osVersion: sizeInfo.osVersion,
  loginBehavior: sizeInfo.loginBehavior,
  isRunningInExpo: sizeInfo.isRunningInExpo,
  isIPhone: sizeInfo.isIPhone,
  isIPad: sizeInfo.isIPad,
  isIPhoneX: sizeInfo.isIPhoneX,
  bottomInset: sizeInfo.bottomInset,
  topInset: sizeInfo.topInset,
  isSimulator: !Constants.isDevice,
  debug,
  ignoredYellowBox: ['Class ABI', 'Module ABI', "Audio doesn't exist"],
github expo / pound-random / pound-random-app / helpers.js View on Github external
onPress: async () => {
            const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
            finalStatus = status;
            if (finalStatus !== 'granted') {
              return;
            }

            let token = await Notifications.getExpoPushTokenAsync();
            // write to db
            await savePushTokenMutation({ variables: { token, userId } });
          },
        },
github Sunghee2 / Myongstagram-ReactNative / client / screens / NotificationScreen.js View on Github external
async registerForPushNotifications() {
    const { status } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
    let finalStatus = status;
  
    if (status !=='granted') {
      const { status } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
      finalStatus = status;
    }
  
    if (finalStatus !== 'granted') {return;}
  
    let token = await Notifications.getExpoPushTokenAsync();
    console.log(token);

    this.props.addPushToken(token);
    this.setState({ isMount: false });
  }
github syousif94 / frugalmaps / frugalapp / src / Permissions.js View on Github external
Alert.alert(
      "Permission Denied",
      "To enable notifications, tap Open Settings and then toggle the Notifications switch.",
      [
        { text: "Cancel", style: "cancel" },
        {
          text: "Open Settings",
          onPress: () => {
            Linking.openURL("app-settings:");
          }
        }
      ]
    );
  }

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

  if (status !== "granted") {
    throw new Error("Permission Denied");
  }
}
github overthq / Auxilium / packages / app / src / api / Auth.ts View on Github external
const authenticate = async (): Promise => {
	const { status: existingStatus } = await Permissions.getAsync(
		Permissions.NOTIFICATIONS
	);
	let finalStatus = existingStatus;
	if (existingStatus !== 'granted') {
		const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
		finalStatus = status;
	} else if (finalStatus !== 'granted') {
		Alert.alert(
			'We require push notification permissions to provide our services.'
		);
	}
	const pushToken = await Notifications.getExpoPushTokenAsync();
	try {
		const response = await fetch(`${env.apiUrl}auth`, {
			method: 'POST',
			headers: {
				Accept: 'application/json',