Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bootstrapAsync = async () => {
// bootstrap the application
// async storage key 'userData' : {
// userToken: String,
// nameornym: String,
// avatarUri: String
// }
try {
// add user permssions
const cam = await Permissions.getAsync(Permissions.CAMERA);
const camr = await Permissions.getAsync(Permissions.CAMERA_ROLL);
// console.warn(cam);
// console.warn(camr);
// load font
await Font.loadAsync({
EurostileRegular: require('../assets/fonts/EurostileRegular.ttf'),
'ApexNew-Book': require('../assets/fonts/ApexNew-Book.otf'),
'ApexNew-Medium': require('../assets/fonts/ApexNew-Medium.otf'),
'ApexNew-Light': require('../assets/fonts/ApexNew-Light.otf'),
});
// load user data
let userData = await AsyncStorage.getItem('userData');
if (userData !== null) {
userData = JSON.parse(userData);
store.dispatch(setUpDefault(userData));
export async function grantCalendar() {
const { status: askStatus } = await Permissions.getAsync(
Permissions.CALENDAR
);
if (IOS && askStatus === "denied") {
throw new Error("Permission Denied");
// Alert.alert(
// "Permission Denied",
// "To enable calendar access, tap Open Settings and then toggle the Calendar switch.",
// [
// { text: "Cancel", style: "cancel" },
// {
// text: "Open Settings",
// onPress: () => {
// Linking.openURL("app-settings:");
// }
// }
export async function registerForPushNotificationsAsync(user_id) {
const { 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;
}
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);
}
export const cameraAccessAsync = async () => {
// get exisiting camera permissions first
const { status: existingStatus } = await Permissions.getAsync(
Permissions.CAMERA
);
let finalStatus = existingStatus;
// ask again to grant camera permissions (if not already allowed)
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
finalStatus = status;
}
return finalStatus === 'granted';
};
onPress = async () => {
const { status } = await Permissions.getAsync(Permissions.CAMERA_ROLL);
if (status !== "granted") {
await Permissions.askAsync(Permissions.CAMERA_ROLL);
}
const imageResult = await ImagePicker.launchImageLibraryAsync({});
if (!imageResult.cancelled) {
const file = new ReactNativeFile({
uri: imageResult.uri,
type: imageResult.type,
name: "picture"
});
const {
field: { name },
form: { setFieldValue }
} = this.props;
setFieldValue(name, file);
}
async function checkPermission() {
const { status: askStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
if (askStatus === "denied") {
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:");
}
}
]