I want to add the following link, as this issue is being discussed also in github
so if any of you is facing the same issue you can follow up the progress.
Are we able to get background location while using the Expo app? The docs state we can, but I am unable to successfully request and get background location
Yes, as i’ve stated, it’s not working currently, i even tried on production apps, but i’m unable to get the required notification.
As per se, google is asking me now a video demostrating, not only how i ask for background permissions but also the functionality itself, pretty anoying.
I hope this gets resolved soon, as i’m unable to get it since updated to SDK43.
So, just for clarity, you were able to set up background permissions in your Expo App, but it’s no longer working, correct? I have been having trouble setting up background location permissions, even in my original version, which was built in SDK 40.
Can’t help you with that, i got the setup much before SDK42, it seems like the latest changes by google about background and foreground geolocation broke a bit the original workflow.
We must wait until they resolve this background issue with the cli to see how to fix it for good on the built app.
TaskManager.defineTask(LOCATION.TRACKING_KEY, async ({ data, error }) => {
// do your logic here in my case i'm emmitting an event and storing data to localStorage.
DeviceEventEmitter.emit("EMMIT_KEY", data );
});
And then i just have this to start location updates:
await Location.startLocationUpdatesAsync("TRACK_KEY", {
accuracy: Location.Accuracy.BestForNavigation,
activityType: Location.ActivityType.AutomotiveNavigation,
enableHighAccuracy: true,
timeInterval: 1000,
// distanceInterval: 10, // minimum change (in meters) betweens updates
// deferredUpdatesInterval: 3000, // minimum interval (in milliseconds) between updates
// foregroundService is how you get the task to be updated as often as would be if the app was open
foregroundService: {
notificationTitle: I18n.t("fGNotificationTitle"),
notificationBody: I18n.t("fGNotificationBody"),
notificationColor: "#59abd6",
},
showsBackgroundLocationIndicator: true,
});
When app comes from background it retrieves stored data, and vice-versa, because
when in background UI updates are not working, so what i do is store it in the background
tasks and then retrieve it and save to the context of the app.
I hadn’t dealt with TaskManager prior to dealing with Background Locations, so I currently have this set up by requesting the Foreground permissions in the first screen, “Screen A”, and then in the following screen (Screen B) I request for background permissions.
Do I keep the TaskManager in the same file I request permissions, or do I put it elsewhere?
Below is what I have:
Screen A’s (foreground) permission request looks like this:
useFocusEffect(
React.useCallback(()=>{
let isActive = true
async function getLocationAsync(){
let{status} = await Location.requestForegroundPermissionsAsync()
if (status !== 'granted'){
setErrorMsg('Permission to access location was denied')
return;
}
let location = await Location.getCurrentPositionAsync({})
setLocation(location)
}
getLocationAsync()
},
[],
),
),
Screen B’s (background) permission request looks like this:
useEffect(()=>{
let isActive = true
const requestBackgroundPermissions = aync() =>{ //Requests permission
const{status} = await Location.requestBackgroundPermissionsAsync()
if (status === 'granted'){
await Location.startLocationUpdateAsync(LOCATION_TASK_NAME,{
accuracy: Location.Accuracy.Balanced
})
}
}
async function getBackgroundLocationAsync(){ //Gets Background Location
let{status} = await Location.requestBackgroundPermissionsAsync()
if (status !== 'granted'){
setErrorMsg('Permission to access background location was denied')
return;
}
let backgroundLocation = await Location.getBackgroundPositionAsync({})
setBackgroundLocation(backgroundLocation)
}
requestBackgroundPermissions()
getBackgroundLocationAsync()
return()=>{
isActive=false
}
},
[],
)
TaskManager Setup
TaskManager.defineTask(LOCATION_TASK_NAME,({data, error})=>{
if(error){
return;
}
if(data){
const{locations}= data
}
})
Sorry, i have no clue with what’s happening to you, i guess it’s just similar to my problem not being hable to get background location to work as expected…
Probably we should need to wait until SDK 44 to see if this problem is fixed.