Skip to content

Commit

Permalink
fix: Make background fetch work (#167)
Browse files Browse the repository at this point in the history
* fix: Make background fetch work

* Return result
  • Loading branch information
amaury1093 authored Aug 16, 2019
1 parent 5bcd7d2 commit 36e2607
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion App/managers/AqiHistoryTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ defineTask(AQI_HISTORY_TASK, () => {
},
() => T.of(Result.NewData)
)
)().catch(logFpError);
)().catch(error => {
logFpError(error);
return Result.Failed;
});
});
7 changes: 4 additions & 3 deletions App/stores/fetchGpsPosition/fetchGpsPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ export function fetchGpsPosition () {
// Start the task to record periodically on the background the location
const isAqiRegistered = await isTaskRegisteredAsync(AQI_HISTORY_TASK);
if (!isAqiRegistered) {
BackgroundFetch.registerTaskAsync(AQI_HISTORY_TASK, {
await BackgroundFetch.registerTaskAsync(AQI_HISTORY_TASK, {
minimumInterval: SAVE_DATA_INTERVAL, // in s
startOnBoot: true,
stopOnTerminate: false
});
// Apparently this is needed on iOS
// Apparently this is needed
// https://github.com/expo/expo/issues/3582#issuecomment-480924126
BackgroundFetch.setMinimumIntervalAsync(SAVE_DATA_INTERVAL);
// https://github.com/expo/expo/issues/3582#issuecomment-520035731
await BackgroundFetch.setMinimumIntervalAsync(SAVE_DATA_INTERVAL);
}

return ExpoLocation.getCurrentPositionAsync({
Expand Down

0 comments on commit 36e2607

Please sign in to comment.