Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getDeviceToken = async () => {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
// パーミッションダイアログを表示します
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
return;
}
const deviceToken = await Notifications.getExpoPushTokenAsync();
if (deviceToken) {
firebase.updateUserToken(deviceToken);
}
}
return async (dispatch, getState) => {
const { user: { token } } = getState();
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus === "denied") {
return;
}
let pushToken = await Notifications.getExpoPushTokenAsync();
console.log(pushToken);
return fetch(`${API_URL}/users/push/`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `JWT ${token}`
async componentDidMount () {
Permissions.askAsync(Permissions.CAMERA_ROLL).then(d => console.log(d))
}
export default (async function registerForPushNotificationsAsync(user, token) {
let { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') return;
let tokenPush = await Notifications.getExpoPushTokenAsync();
if(tokenPush == user.push_token) return;
return fetch(PUSH_ENDPOINT, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': token //JWT Token
},
body: JSON.stringify({
token: tokenPush
}),
});
});
"To enable notifications, tap Open Settings and then toggle the Notifications switch.",
[
{ text: "Cancel", style: "cancel" },
{
text: "Open Settings",
onPress: () => {
Linking.openURL("app-settings:");
}
}
]
);
return askStatus;
}
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
return status;
}
onUserPress = async () => {
const { me, dispatch } = this.props;
const permissions = Permissions.CAMERA_ROLL;
const { status } = await Permissions.askAsync(permissions);
if (status) {
const photo = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [1, 1],
});
if (!photo.cancelled) {
const response = await firebase.changeUserImg(photo);
if (!response.error) {
dispatch({
type: 'ME_SET', payload: { ...me, img: photo.uri },
});
}
}
}
onTabPress = async (mode = 'photo', headerTitle = I18n.t('Take.tab2')) => {
const { flashMode } = this.state;
const { navigation } = this.props;
if (mode !== 'library') {
this.setState({
mode,
flashMode: (mode === 'photo') ? flashMode : Camera.Constants.FlashMode.off,
});
navigation.setParams({
headerTitle,
});
} else {
const permissions = Permissions.CAMERA_ROLL;
const { status } = await Permissions.askAsync(permissions);
if (status) {
const photo = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [1, 1],
});
if (!photo.cancelled) {
navigation.push('TakePublish', { mode: 'photo', photo });
}
}
}
}
askPermissionsAsync = async () => {
await Permissions.askAsync(Permissions.CAMERA_ROLL)
}