Expo location tracking on iOS - abnormal api requests time

Hello!

Expo SDK 37
iOS only
only on app store / test flight app

I’m using Location.startLocationUpdatesAsync and it works perfectly on Android devices, but not on iOS.

I know, that due to new Apple conditions, i need to add this part

infoPlist": {
        "NSLocationWhenInUseUsageDescription": "text",
        "NSLocationAlwaysAndWhenInUseUsageDescription": "text",
        "NSLocationAlwaysUsageDescription": "text",

to my app.json file, to use background location on iOS, but the problem is, that my app is lagging, while its on foreground of the screen.
After, let say, opening new screen, loading data from API takes sometimes 30 seconds, sometimes 2 minutes etc…

When i turn location tracking off, it works good.

I have changed Location.Accuracy to Balanced for test, but it’s still laggy.
I have logger turned off and dont have any console logs in my task definition.

How can i avoid this behavior? Do i need any additional task configuration?

My code below.

 const trackingActive = await Location.hasStartedLocationUpdatesAsync('background-location-task');

                if (!trackingActive) {
                        await Location.startLocationUpdatesAsync('background-location-task', {

                            accuracy: Location.Accuracy.High,
                            showsBackgroundLocationIndicator: true,
                            foregroundService: {
                                notificationTitle: 'App name',
                                notificationBody: 'GPS is On',
                                notificationColor: '#FFFFFF',
                            }
                        });


TaskManager.defineTask('background-location-task', ({data, error}) => {
    if (error) {
        alert('error');
        return;
    }
    if (data) {
        const {locations}: any = data;
        const lat = (locations.map((item: { coords: { latitude: any; }; }) => item.coords.latitude).toString()).substring(0, 10);
        const lng = (locations.map((item: { coords: { longitude: any; }; }) => item.coords.longitude).toString()).substring(0, 10);

        axios.put(`/my/test/api`, {
            lat, lng
        }).then();
    }
});

Hope that somebody can help me!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.