Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
}
}
async function getSavedLocations() {
try {
const item = await AsyncStorage.getItem(STORAGE_KEY);
return item ? JSON.parse(item) : [];
} catch (e) {
return [];
}
}
TaskManager.defineTask(LOCATION_UPDATES_TASK, async ({ data: { locations } }: any) => {
if (locations && locations.length > 0) {
const savedLocations = await getSavedLocations();
const newLocations = locations.map(({ coords }: any) => ({
latitude: coords.latitude,
longitude: coords.longitude,
}));
// tslint:disable-next-line no-console
console.log(`Received new locations at ${new Date()}:`, locations);
savedLocations.push(...newLocations);
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(savedLocations));
locationEventsEmitter.emit('update', savedLocations);
}
});
/>
<button title="Center">
);
}
}
async function getSavedRegions(): Promise {
const tasks = await TaskManager.getRegisteredTasksAsync();
const task = tasks.find(({ taskName }) => taskName === GEOFENCING_TASK);
return task ? task.options.regions : [];
}
TaskManager.defineTask(GEOFENCING_TASK, async ({ data: { region } }: { data: any }) => {
const stateString = Location.GeofencingRegionState[region.state].toLowerCase();
// tslint:disable-next-line no-console
console.log(`${stateString} region ${region.identifier}`);
await Notifications.presentLocalNotificationAsync({
title: 'Expo Geofencing',
body: `You're ${stateString} a region ${region.identifier}`,
data: region,
});
});
const styles = StyleSheet.create({
screen: {
flex: 1,
},</button>
);
}
}
async function getSavedLocations() {
try {
const item = await AsyncStorage.getItem(STORAGE_KEY);
return item ? JSON.parse(item) : [];
} catch (e) {
return [];
}
}
if (Platform.OS !== 'android') {
TaskManager.defineTask(LOCATION_UPDATES_TASK, async ({ data: { locations } }) => {
if (locations && locations.length > 0) {
const savedLocations = await getSavedLocations();
const newLocations = locations.map(({ coords }) => ({
latitude: coords.latitude,
longitude: coords.longitude,
}));
savedLocations.push(...newLocations);
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(savedLocations));
locationEventsEmitter.emit('update', savedLocations);
}
});
}
const styles = StyleSheet.create({
};
const loadAssets = () => {
const images = [
require('../assets/Notify.png'),
require('../assets/Help_Others.png'),
require('../assets/Security.png')
];
images.map(image => Asset.fromModule(image).downloadAsync());
};
if (!fontsLoaded) return ;
return ;
};
TaskManager.defineTask(LOCATION_TASK, ({ data, error }: any) => {
if (error) console.log(error);
if (data) {
const { locations } = data;
const {
coords: { longitude, latitude }
} = locations[0] as { coords: EmergencyCoordinates };
setInterval(() => {
Emergencies.managePushNotifications({ longitude, latitude });
}, 10000);
}
});
export default Root;
<button title="{">
);
}
}
TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
const now = Date.now();
console.log(`Got background fetch call at date: ${new Date(now).toISOString()}`);
await AsyncStorage.setItem(LAST_FETCH_DATE_KEY, now.toString());
return BackgroundFetch.Result.NewData;
});
const styles = StyleSheet.create({
screen: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
button: {
padding: 10,</button>
);
}
}
async function getSavedRegions() {
const tasks = await TaskManager.getRegisteredTasksAsync();
const task = tasks.find(({ taskName }) => taskName === GEOFENCING_TASK);
return task ? task.options.regions : [];
}
if (Platform.OS !== 'android') {
TaskManager.defineTask(GEOFENCING_TASK, async ({ data: { region } }) => {
const stateString = Location.GeofencingRegionState[region.state].toLowerCase();
const body = `You're ${stateString} a region with latitude: ${region.latitude}, longitude: ${region.longitude} and radius: ${region.radius}m`;
await Notifications.presentLocalNotificationAsync({
title: 'Expo Geofencing',
body,
data: {
...region,
notificationBody: body,
notificationType: GEOFENCING_TASK,
},
});
});
}
Notifications.addListener(({ data, remote }) => {
export async function registerTaskAsync(taskName: string, options: BackgroundFetchOptions = {}): Promise {
if (!ExpoBackgroundFetch.registerTaskAsync) {
throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync')
}
if (!TaskManager.isTaskDefined(taskName)) {
throw new Error(
`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`
);
}
await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function registerTaskAsync(taskName, options = {}) {
if (!ExpoBackgroundFetch.registerTaskAsync) {
throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync');
}
if (!TaskManager.isTaskDefined(taskName)) {
throw new Error(`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`);
}
await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function unregisterTaskAsync(taskName) {
export async function registerTaskAsync(taskName: string, options: BackgroundFetchOptions = {}): Promise {
if (!ExpoBackgroundFetch.registerTaskAsync) {
throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync')
}
if (!TaskManager.isTaskDefined(taskName)) {
throw new Error(
`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`
);
}
await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function registerTaskAsync(taskName, options = {}) {
if (!ExpoBackgroundFetch.registerTaskAsync) {
throw new UnavailabilityError('BackgroundFetch', 'registerTaskAsync');
}
if (!TaskManager.isTaskDefined(taskName)) {
throw new Error(`Task '${taskName}' is not defined. You must define a task using TaskManager.defineTask before registering.`);
}
await ExpoBackgroundFetch.registerTaskAsync(taskName, options);
}
export async function unregisterTaskAsync(taskName) {