This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { View, Text } from "react-native"; | |
import { Permissions } from "expo"; | |
class PermissionsExample extends React.Component { | |
state = { | |
message: "" | |
}; | |
async componentWillMount() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setUserCity = async (city) => { | |
try { | |
await AsyncStorage.setItem("userCity", city); | |
} catch (error) { | |
console.log(`While storing userCity: ${error.message}`); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getUserCity = async () => { | |
try { | |
return await AsyncStorage.getItem("userCity"); | |
catch (error) { | |
console.log(`While getting userCity: ${error.message}`); | |
return null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deleteUserCity = async () => { | |
try { | |
await AsyncStorage.removeItem("userCity"); | |
} catch (error) { | |
console.log(`While removing userCity: ${error.message}`); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App extends React.Component { | |
state = { | |
notification: "" | |
}; | |
registerForPushNotificationsAsync = async () => { | |
// Same as earlier | |
} | |
handleNotification = notification => { |