Skip to content

Instantly share code, notes, and snippets.

import React from "react";
import { View, Text, StyleSheet, Button } from "react-native";
import { Auth } from "aws-amplify";
import { withAuthContext } from "../context";
class Home extends React.Component {
handleLogout = async () => {
await Auth.signOut();
this.props.auth.setAuthenticated(false);
};
import React from "react";
import { View, Text } from "react-native";
import { Permissions } from "expo";
class PermissionsExample extends React.Component {
state = {
message: ""
};
async componentWillMount() {
import React from "react";
import { View, Text, Platform } from "react-native";
import { Constants, Location, Permissions } from "expo";
class PermissionsExample extends React.Component {
state = {
message: null,
location: null
};
setUserCity = async (city) => {
try {
await AsyncStorage.setItem("userCity", city);
} catch (error) {
console.log(`While storing userCity: ${error.message}`);
}
}
getUserCity = async () => {
try {
return await AsyncStorage.getItem("userCity");
catch (error) {
console.log(`While getting userCity: ${error.message}`);
return null;
}
}
deleteUserCity = async () => {
try {
await AsyncStorage.removeItem("userCity");
} catch (error) {
console.log(`While removing userCity: ${error.message}`);
}
}
import { Permissions } from "expo";
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.
import { Notifications, Permissions } from "expo";
const PUSH_ENDPOINT = "https://your-push-server/push-token"
async function registerForPushNotificationsAsync() {
// Request permissions -- same as earlier
[...]
// Get the token that uniquely identifies this device
const token = await Notifications.getExpoPushTokenAsync();
const EXPO_HOST = "https://exp.host/--/api/v2/push/send";
function sendNotification(token, title, body) {
return fetch(EXPO_HOST, {
body: JSON.stringify({
to: token,
title: title,
body: body
}),
headers: {
class App extends React.Component {
state = {
notification: ""
};
registerForPushNotificationsAsync = async () => {
// Same as earlier
}
handleNotification = notification => {