-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate push token #170
base: master
Are you sure you want to change the base?
Generate push token #170
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Notifications } from 'expo'; | ||
import * as Permissions from 'expo-permissions'; | ||
import {Alert} from 'react-native'; | ||
|
||
const PUSH_ENDPOINT = 'https://your-server.com/users/push-token'; | ||
|
||
export default async function registerForPushNotificationsAsync() { | ||
const { status: existingStatus } = await Permissions.getAsync( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if there's a better place to keep P.N. related stuff. Using the libs dir might make sense if there isn't a more intuitive place. |
||
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(); | ||
|
||
// lets see if we can display it as an alert... | ||
Alert.alert('Push Token', token); | ||
|
||
|
||
// POST the token to your backend server from where you can retrieve it to send push notifications. | ||
// return fetch(PUSH_ENDPOINT, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously we would want to send the token to the server using redux and the appropriate actions. |
||
// method: 'POST', | ||
// headers: { | ||
// Accept: 'application/json', | ||
// 'Content-Type': 'application/json', | ||
// }, | ||
// body: JSON.stringify({ | ||
// token: { | ||
// value: token, | ||
// }, | ||
// user: { | ||
// username: 'Brent', | ||
// }, | ||
// }), | ||
// }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import commonStyles from '../../styles/common'; | |
import MoneyMeter from '../../components/money-meter'; | ||
import MenuCircle from '../../components/menu-circle'; | ||
import GoalsBox from '../../components/goals-box'; | ||
import getPushToken from '../../libs/pushTokens' | ||
|
||
import pkg from '../../package.json'; | ||
|
||
|
@@ -84,6 +85,10 @@ class Dashboard extends Component<PropsType> { | |
} | ||
} | ||
|
||
pushTokenAlert() { | ||
getPushToken() | ||
} | ||
|
||
ellipsisLogoutAlert() { | ||
const logoutCallback = this.props.actions.logout; | ||
|
||
|
@@ -162,7 +167,7 @@ class Dashboard extends Component<PropsType> { | |
}} | ||
> | ||
<TouchableHighlight | ||
onPress={() => this.ellipsisLogoutAlert()} | ||
onPress={() => this.pushTokenAlert()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how I triggered the push token generation. |
||
underlayColor='transparent' | ||
style={{ | ||
width: 300, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this branch uses this function yet.