Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In background mode on iOS, plugin freeze the app #1388

Open
kukareku0307 opened this issue Nov 29, 2024 · 5 comments
Open

In background mode on iOS, plugin freeze the app #1388

kukareku0307 opened this issue Nov 29, 2024 · 5 comments

Comments

@kukareku0307
Copy link

Your Environment

  • Plugin version: 4.16.4
  • Platform: iOS
  • OS version: 17
  • Device manufacturer / model: iPhone
  • Flutter info (flutter doctor):
  • Plugin config:
bg.Config(
        stopDetectionDelay: 0,
        maxRecordsToPersist: 2,
        stopTimeout: 0,
        httpTimeout: 10000,
        disableElasticity: true,
        stationaryRadius: 25,
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
        distanceFilter: 15.0,
        url: Url,
        stopOnTerminate: false,
        startOnBoot: true,
        debug: true,
        showsBackgroundLocationIndicator: false,
        disableLocationAuthorizationAlert: true,
        logLevel: bg.Config.LOG_LEVEL_INFO);
        +
        main:
         LocationService.state = await bg.BackgroundGeolocation.ready(
            LocationService.buildLocationConfig());
        kfromBackgroundLocationAppStarted_ =
            LocationService.state?.didLaunchInBackground ?? false;
        

Expected Behavior

When I turn off the application, the plugin turns on in the background and works as it should, it turns on and off by the system when necessary.

Actual Behavior

When I force quit the application, the plugin turns on in the background and works as it should, it turns on and off by the system when necessary, BUT after some time, I can assume that iOS turns off the application as unnecessary in the background and after a while, due to a small movement, the plugin tries to turn on and writes in the debug notification: "Authorization status changed 3" and that's it, after this happens, if I enter the app then it just freezes on the splash screen and nothing happens. It doesn't happen often, but it does.

Steps to Reproduce

Context

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
@christocracy
Copy link
Member

See wiki “Debugging”. Use LOG_LEVEL_VERBOSE. Learn to fetch logs using method .emailLog.

I have never experienced this behaviour with the /example app in this repo. I field-test almost every day for years.

@kukareku0307
Copy link
Author

kukareku0307 commented Nov 30, 2024

LOG_LEVEL_VERBOSE

2024-11-30 15:43:26.219 ✅-[BackgroundTaskManager createBackgroundTask] 20

2024-11-30 15:43:26.229 ✅-[TSHttpService schedulePost] LOCKED: 3651F591-BC8E-4E0C-9FF7-CE6CEF496B55

2024-11-30 15:43:35.574
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:43:36.411 ⚠️-[HttpResponse handleResponse] HTTP ERROR: 0

NSLocalizedDescription = "\U041f\U0440\U0435\U0432\U044b\U0448\U0435\U043d \U043b\U0438\U043c\U0438\U0442 \U0432\U0440\U0435\U043c\U0435\U043d\U0438 \U043d\U0430 \U0437\U0430\U043f\U0440\U043e\U0441.";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1001 \"(null)\" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}";
"_NSURLErrorFailingURLSessionTaskErrorKey" = "LocalDataTask <B90C0300-A2FC-4442-B456-B43E68BCFB80>.<1>";
"_NSURLErrorRelatedURLSessionTaskErrorKey" =     (
    "LocalDataTask <B90C0300-A2FC-4442-B456-B43E68BCFB80>.<1>"
);
"_kCFStreamErrorCodeKey" = "-2102";
"_kCFStreamErrorDomainKey" = 4;

}

2024-11-30 15:43:36.426 ✅-[TSHttpService post:]_block_invoke UNLOCKED: 3651F591-BC8E-4E0C-9FF7-CE6CEF496B55

2024-11-30 15:43:36.426
╔═══════════════════════════════════════════════════════════
║ -[TSHttpService finish:error:] Success: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:43:36.426 ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 20 OF (
20
)

2024-11-30 15:43:38.143
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/66 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:43:48.456
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:01.012
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:01.012 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-11-30 15:44:01.334
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:01.334 ℹ️-[TSLocationManager resetMotionTriggerTimer]

2024-11-30 15:44:02.946
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:02.946 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-11-30 15:44:03.586
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:03.586 ℹ️-[TSLocationManager resetMotionTriggerTimer]

2024-11-30 15:44:11.966
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:11.966 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-11-30 15:44:12.287
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:12.287 ℹ️-[TSLocationManager resetMotionTriggerTimer]

2024-11-30 15:44:13.256
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:13.256 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-11-30 15:44:13.575
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:13.575 ℹ️-[TSLocationManager resetMotionTriggerTimer]

2024-11-30 15:44:22.271
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | on_foot/100 | isMoving: 1
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:23.561
╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════

2024-11-30 15:44:23.561 🔵-[TSLocationManager startMotionTriggerTimer] Motion-trigger timer engaged: Stop-detection will trigger in 10 seconds...

2024-11-30 17:28:33.516 ℹ️-[TSDBLogger db_delete] maxAge: 259200

2024-11-30 17:28:33.517 ℹ️-[TSLocationManager init]
╔═════════════════════════════════════════════
║ TSLocationManager (build 388)
╠══════════════════════════════════════════════
{
activityRecognitionInterval = 10000;
activityType = 1;
authorization = {
};
autoSync = 1;
autoSyncThreshold = 0;
batchSync = 0;
debug = 1;
desiredAccuracy = "-2";
desiredOdometerAccuracy = 100;
didDeviceReboot = 0;
didLaunchInBackground = 0;
didRequestUpgradeLocationAuthorization = 1;
disableAutoSyncOnCellular = 0;
disableElasticity = 1;
disableLocationAuthorizationAlert = 1;
disableMotionActivityUpdates = 0;
disableStopDetection = 0;
distanceFilter = 15;
elasticityMultiplier = 1;
enableTimestampMeta = 0;
enabled = 1;
extras = {
};
geofenceInitialTriggerEntry = 1;
geofenceProximityRadius = 2000;
geofenceTemplate = "";
headers = {
};
heartbeatInterval = 60;
httpRootProperty = location;
httpTimeout = 10000;
iOSHasWarnedLocationServicesOff = 0;
isFirstBoot = 0;
isMoving = 0;
lastLocationAuthorizationStatus = 3;
locationAuthorizationAlert = {
};
locationAuthorizationRequest = Always;
locationTemplate = "";
locationTimeout = 60;
locationsOrderDirection = ASC;
logLevel = 5;
logMaxDays = 3;
maxBatchSize = "-1";
maxDaysToPersist = 1;
maxRecordsToPersist = 2;
method = POST;
minimumActivityRecognitionConfidence = 70;
odometer = "27083.48257503652";
params = {
"user_id" = 12;
};
pausesLocationUpdatesAutomatically = 1;
persistMode = 2;
preventSuspend = 0;
schedule = (
);
schedulerEnabled = 0;
showsBackgroundLocationIndicator = 0;
startOnBoot = 1;
stationaryRadius = 25;
stopAfterElapsedMinutes = "-1";
stopDetectionDelay = 0;
stopOnStationary = 0;
stopOnTerminate = 0;
stopTimeout = 0;
trackingMode = 1;
triggerActivities = "";
url = "_";
useSignificantChangesOnly = 0;
}

2024-11-30 17:28:33.520 ℹ️-[GeofenceDAO init] CREATE TABLE IF NOT EXISTS geofences (id INTEGER PRIMARY KEY AUTOINCREMENT, identifier TEXT NOT NULL UNIQUE, latitude DOUBLE NOT NULL, sin_latitude DOUBLE NOT NULL, cos_latitude DOUBLE NOT NULL, longitude DOUBLE NOT NULL, sin_longitude DOUBLE NOT NULL, cos_longitude DOUBLE NOT NULL, radius DOUBLE NOT NULL, notifyOnEntry BOOLEAN NOT NULL DEFAULT 0, notifyOnExit BOOLEAN NOT NULL DEFAULT 0, notifyOnDwell BOOLEAN NOT NULL DEFAULT 0, loiteringDelay DOUBLE NOT NULL DEFAULT 0, extras TEXT, vertices TEXT)

2024-11-30 17:28:33.520 ℹ️-[GeofenceDAO init] CREATE index IF NOT EXISTS identifier ON geofences (identifier);CREATE index IF NOT EXISTS latitude ON geofences (latitude);CREATE index IF NOT EXISTS longitude ON geofences (longitude);CREATE index IF NOT EXISTS sin_latitude ON geofences (sin_latitude);CREATE index IF NOT EXISTS cos_latitude ON geofences (cos_latitude);CREATE index IF NOT EXISTS sin_longitude ON geofences (sin_longitude);CREATE index IF NOT EXISTS cos_longitude ON geofences (cos_longitude);

2024-11-30 17:28:33.567 🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 3

2024-11-30 17:28:33.574 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-11-30 17:28:33.575 🔵-[PolygonGeofencingService locationManager:didChangeAuthorizationStatus:] 3

2024-11-30 17:28:33.575 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-11-30 17:28:33.575 🔵-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 3

2024-11-30 17:28:33.575 🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 3

2024-11-30 17:28:33.588 ℹ️+[LocationAuthorization run:onCancel:] status: 3

Here in 17:28:33.588 is the last log when freezes.

@christocracy
Copy link
Member

Show me all your dart code where you're interacting with BackgroundGeolocation.

@kukareku0307
Copy link
Author

kukareku0307 commented Nov 30, 2024

Show me all your dart code where you're interacting with BackgroundGeolocation.

 if (Platform.isAndroid) {
      LocationService.state = await bg.BackgroundGeolocation.ready(
          LocationService.buildLocationConfig());
      kfromBackgroundLocationAppStarted_ =
          LocationService.state?.didLaunchInBackground ?? false;
    } else if (!kfromBackgroundLocationAppStarted_) {
      kfromBackgroundLocationAppStarted_ =
          await Notifications.checkBackgroundStart() ?? false;
      if (kfromBackgroundLocationAppStarted_) {
        LocationService.state = await bg.BackgroundGeolocation.ready(
            LocationService.buildLocationConfig());
        if (LocationService.state?.enabled == false) {
          bg.BackgroundGeolocation.start();
        }
      } else {
        LocationService.state = await bg.BackgroundGeolocation.ready(
            LocationService.buildLocationConfig());
        kfromBackgroundLocationAppStarted_ =
            LocationService.state?.didLaunchInBackground ?? false;
        if (kfromBackgroundLocationAppStarted_) {
          if (LocationService.state?.enabled == false) {
            bg.BackgroundGeolocation.start();
          }
        }
      }
    }
    LocationService.geoCallbacks(false);
It is in main function in flutter when app is launching.

`Notifications.checkBackgroundStart()` checks in swift: launchOptions: `[UIApplication.LaunchOptionsKey: Any]?` whether it has .location key

@christocracy
Copy link
Member

LocationService.state

What is this? bg.BackgroundGeolocation.ready returns an instance of bg.State.

You seem to have added some sort of wrapper around the plugin's API. Perhaps you have a problem there. I suggest you temporarily remove all this logic around this "kfromBackgroundLocationAppStarted_ and checkBackgroundStart and attempt to reproduce without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants