Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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: {
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,
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 });
}
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"],
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 } });
},
},
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 });
}
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");
}
}
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',