How to use the expo.Notifications.getExpoPushTokenAsync 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
// 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: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      token: {
        value: token
      },
      user: {
        username: 'Brent'
      }
    })
github rotembcohen / pokerBuddyApp / UtilFunctions.js View on Github external
// 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();

	// POST the token to our backend so we can use it to send pushes from there
	response = await fetchFromServer('users/'+ user_id +'/push_token/','POST',{
			push_token: token,
		},null);
	
	if (response.status === 200){
		user = await response.json();
		return {user: user,error:'None'};
	}

	return {error:'Server Error'};
}
github Vivify-Ideas / expo-boilerplate / services / PermissionsService.js View on Github external
// 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 w771854332 / rn-twitter / src / api / registerForPushNotificationsAsync.js View on Github external
// Remote notifications do not work in simulators, only on device
  if (!Constants.isDevice) {
    return;
  }

  // Android remote notification permissions are granted during the app
  // install, so this will only ask on iOS
  let { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

  // Stop here if the user did not grant permissions
  if (status !== "granted") {
    return;
  }

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

  // POST the token to our backend so we can use it to send pushes from there
  return fetch(PUSH_ENDPOINT, {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      token: {
        value: token
      }
    })
  });
}
export default registerForPushNotificationsAsync
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 / Notifications.js View on Github external
async function syncReminder(id, state) {
  try {
    const token = await Notifications.getExpoPushTokenAsync();
    await api("sync-reminder", {
      state,
      id,
      token
    });
  } catch (error) {
    console.log(error);
  }
}
github molenzwiebel / Mimic / frontend / utils / notifications.ts View on Github external
export async function updateNotificationTokens() {
    const settings = await withComputerConfig();
    const response = await Permissions.getAsync(Permissions.NOTIFICATIONS);

    if (!response.granted) {
        await socket.registerPushNotificationToken(NotificationType.CLEAR, null);
        await socket.registerPushNotificationToken(NotificationType.GAME_STARTED, null);
        await socket.registerPushNotificationToken(NotificationType.READY_CHECK, null);

        return;
    }

    const token = await Notifications.getExpoPushTokenAsync();

    await socket.registerPushNotificationToken(NotificationType.CLEAR, token);
    await socket.registerPushNotificationToken(
        NotificationType.GAME_STARTED,
        settings.gameStartNotificationsEnabled ? token : null
    );
    await socket.registerPushNotificationToken(
        NotificationType.READY_CHECK,
        settings.readyCheckNotificationsEnabled ? token : null
    );
}
github just1and0 / expo-push-notification-helper / Helpers / getToken.js View on Github external
getToken: async ()=>{
       const token = await Notifications.getExpoPushTokenAsync();
       return token;
    },