Skip to content

[Bug]: The service suddenly stops at regular intervals on iOS devices #1641

@disastechapp

Description

@disastechapp

Required Reading

  • Confirmed

Plugin Version

5.0.4

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.9, on macOS 26.2 25C56 darwin-arm64, locale en-TR)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 26.0)
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
    ! Error: Browsing on the local area network for iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

• No issues found!

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

iPhone 15

Device operating-systems(s)

18.1

What happened?

The sample logs show the following scenario:

  • [2026-02-24T22:25:30.124200][🔋: 65%] * Surus basladi..
  • ...
  • [2026-02-24T22:26:51.690377][🔋: 60%] [APP] Uygulama inactive (gecis durumu)

This scenario occurs too many times during the day on this device. Shortly after the ride starts, it is terminated, and then the service wakes up again in rides 1-2 hours later. However, losses occur during the 2 hours in between.

When “preventSuspend: true” is set, restrictions occur on iOS devices and background services are completely suspended after 2-3 days of use.

How do I update the settings to avoid restrictions?
Why does it end immediately after starting the ride? (This only happens on some devices; it is not a common problem for all devices)

Plugin Code and/or Config

await bg.BackgroundGeolocation.ready(bg.Config(
      debug: kDebugMode,
      app: bg.AppConfig(
        stopOnTerminate: false,
        startOnBoot: true,
        enableHeadless: true,
        heartbeatInterval: _getSafeHeartbeatInterval(service),
        schedule: [],
        backgroundPermissionRationale: bg.PermissionRationale(
          title: AppLocalizations.of(ContextUtility.context!)!
              .trackingPermissionBackgroundTitle,
          message: AppLocalizations.of(ContextUtility.context!)!
              .trackingPermissionBackgroundMessage,
          positiveAction:
              AppLocalizations.of(ContextUtility.context!)!.givePermission,
          negativeAction:
              AppLocalizations.of(ContextUtility.context!)!.cancellation,
        ),
        notification: bg.Notification(
          sticky: true,
          channelId: 'my_channel_id',
          actions: ["notificationButtonFoo", "notificationButtonBar"],
          priority: bg.NotificationPriority.max,
          title: "Konum Servisi",
          text: "Disastech ile her an güvendesiniz 🛡",
          smallIcon: "drawable/icon",
          largeIcon: "drawable/icon",
        ),
      ),

      // 2. Geolocation ve Filtreleme Seçenekleri
      geolocation: bg.GeoConfig(
        desiredAccuracy: bg.DesiredAccuracy.high,
          locationUpdateInterval: 1000,
        fastestLocationUpdateInterval: 500,
        deferTime: 0,
        geofenceModeHighAccuracy: true,
        distanceFilter: _getSafeDistanceFilter(service),
        stopTimeout: 15,
        stationaryRadius: 25,
        elasticityMultiplier: Platform.isAndroid ? 2.0 : 1.0,
        geofenceInitialTriggerEntry: true,
        geofenceProximityRadius: 1000,
        pausesLocationUpdatesAutomatically: false,
        activityType: bg.ActivityType.other,
      ),
      geofenceModeHighAccuracy: true,

      // 3. Log ve Debug Seçenekleri
      logger: const bg.LoggerConfig(
        debug: false,
        logLevel: bg.LogLevel.verbose,
        logMaxDays: 3,
      ),

      // 4. Veri Saklama Seçenekleri
      persistence: bg.PersistenceConfig(
        maxDaysToPersist: 3,
        extras: {
          "userId": userId,
          "gsm": gsm,
          "countryCode": countryCode,
        },
      ),

      locationAuthorizationAlert: {
        "titleWhenNotEnabled": "Arka Planda Konum Kapalı",
        "titleWhenOff": "Konum Servisi Kapalı",
        "instructions":
            "Arka planda konum takibi yapabilmek için konum iznini 'Her Zaman' olarak ayarlamanız gerekmektedir.",
        "cancelButton": "İptal",
        "settingsButton": "Ayarlar"
      },

      activity: const bg.ActivityConfig(
        activityRecognitionInterval: 5000,
        minimumActivityRecognitionConfidence: 50,
        disableStopDetection: false,
      ),

      // Üst Seviye Kontrol Parametreleri
      reset: true,
      isMoving: true,
      allowIdenticalLocations: true,
      enableTimestampMeta: true,
    )).then((bg.State state) async {
      TrackingService.fetchAndUpdateUsers();
      trackingLogPrint('[ready] SUCCESS: ${state.toMap()}');

      if (state.schedule != null && state.schedule!.isNotEmpty) {
        bg.BackgroundGeolocation.startSchedule();
      }
    }).catchError((error) {
      trackingLogPrint('[ready] ERROR: $error');
    });

Relevant log output

[2026-02-24T22:26:23.053324][🔋: 60%] * [processLocation] Speed: 13.6 km/h, Driving: true, Timer: false
[2026-02-24T22:26:24.057543][🔋: 60%] * [processLocation] Speed: 12.8 km/h, Driving: true, Timer: false
[2026-02-24T22:26:24.062201][🔋: 60%] * [processLocation] Speed: 12.8 km/h, Driving: true, Timer: false
[2026-02-24T22:26:31.060079][🔋: 60%] * [processLocation] Speed: 17.5 km/h, Driving: true, Timer: false
[2026-02-24T22:26:31.516716][🔋: 60%] * [Headless] Konum gonderildi (speed: 17.5 km/h)
[2026-02-24T22:26:40.064796][🔋: 60%] * [processLocation] Speed: 18.1 km/h, Driving: true, Timer: false
[2026-02-24T22:26:40.222394][🔋: 60%] [APP] Uygulama ON PLANA geldi (resumed)
[2026-02-24T22:26:40.571844][🔋: 60%] * [Headless] Konum gonderildi (speed: 18.1 km/h)
[2026-02-24T22:26:51.690377][🔋: 60%] [APP] Uygulama inactive (gecis durumu)
[2026-02-25T00:31:08.896776] * TrackingService created: hash=62671822
[2026-02-25T00:31:08.897757] ✅ Geofence listesi basariyla guncellendi.
, 11 toplam aktif
[2026-02-25T00:31:09.268365] [distanceFilter] RemoteConfig degeri kullaniliyor: 25.0
aniliyor: 900.0
[2026-02-25T00:31:09.274885][🔋: 55%] [providerchange] - [ProviderChangeEvent enabled:true, status: 3, network: true, gps: true, accuracyAuthorization: 0]
lse, elasticityMultiplier: 1.0, enableTimestampMeta: true, useSignificantChangesOnly: false, disableLocationAuthorizationAlert: false, stationaryRadius: 25, stopTimeout: 15, stopAfterElapsedMinutes: -1, geofenceProximityRadius: 2000, geofenceInitialTriggerEntry: true, filter: {policy: 2, useKalman: true, kalmanDebug: false, kalmanProfile: 0, rollingWindow: 5, burstWindow: 10.0, maxBurstDistance: 300.0, trackingAccuracyThreshold: 100.0, maxImpliedSpeed: 60.0, filterDebug: false, odometerUseKalmanFilter: true, odometerAccuracyThreshold: 20.0}, pausesLocationUpdatesAutomatically: false, showsBackgroundLocationIndicator: true, activityType: 1, locationAuthorizationAlert: {settingsButton: Ayarlar, cancelButton: Iptal, titleWhenNotEnabled: Arka Planda Konum Kapali, instructions: Arka planda konum takibi yapabilmek icin konum iznini 'Her Zaman' olarak ayarlamaniz gerekmektedir., titleWhenOff: Konum Servisi Kapali}}, app: {stopOnTerminate: false, startOnBoot: true, heartbeatInterval: 900.0, schedule: [], preventSuspend: false}, http: {autoSync: true, autoSyncThreshold: 0, disableAutoSyncOnCellular: false, batchSync: false, maxBatchSize: -1, method: POST, url: , params: {}, headers: {}, rootProperty: location, timeout: 60000}, activity: {activityRecognitionInterval: 5000.0, minimumActivityRecognitionConfidence: 50, disableStopDetection: false, stopOnStationary: false, triggerActivities: , disableMotionActivityUpdates: false, stopDetectionDelay: 0.0}, persistence: {locationTemplate: , geofenceTemplate: , maxDaysToPersist: 3, maxRecordsToPersist: -1, locationsOrderDirection: ASC, persistMode: 2, extras: {gsm: 5322875281, userId: 1294, countryCode: +90}}, logger: {debug: false, logLevel: 5, logMaxDays: 3}, desiredAccuracy: -1, distanceFilter: 25.0, stationaryRadius: 25.0, locationTimeout: 60, disableElasticity: false, elasticityMultiplier: 1.0, stopAfterElapsedMinutes: -1, geofenceProximityRadius: 2000, geofenceInitialTriggerEntry: true, useSignificantChangesOnly: false, isMoving: true, stopTimeout: 15, activityRecognitionInterval: 5000, minimumActivityRecognitionConfidence: 50, disableStopDetection: false, stopOnStationary: false, url: , persistMode: 2, method: POST, httpRootProperty: location, params: {}, headers: {}, extras: {gsm: 5322875281, userId: 1294, countryCode: +90}, autoSync: true, disableAutoSyncOnCellular: false, autoSyncThreshold: 0, batchSync: false, maxBatchSize: -1, locationTemplate: , geofenceTemplate: , maxDaysToPersist: 3, maxRecordsToPersist: -1, locationsOrderDirection: ASC, httpTimeout: 60000, authorization: {strategy: JWT, accessToken: , refreshToken: , refreshUrl: , refreshPayload: {}, refreshHeaders: {Authorization: Bearer {accessToken}}, expires: -1}, stopOnTerminate: false, startOnBoot: true, heartbeatInterval: 900, schedule: [], scheduleUseAlarmManager: false, debug: false, logLevel: 5, logMaxDays: 3, pausesLocationUpdatesAutomatically: false, locationAuthorizationRequest: Always, locationAuthorizationAlert: {settingsButton: Ayarlar, cancelButton: Iptal, titleWhenNotEnabled: Arka Planda Konum Kapali, instructions: Arka planda konum takibi yapabilmek icin konum iznini 'Her Zaman' olarak ayarlamaniz gerekmektedir., titleWhenOff: Konum Servisi Kapali}, disableLocationAuthorizationAlert: false, showsBackgroundLocationIndicator: true, activityType: 1, stopDetectionDelay: 0, disableMotionActivityUpdates: false, preventSuspend: false, enableTimestampMeta: true, triggerActivities: }
[2026-02-25T00:31:09.277216][🔋: 55%] [ProviderChange] Tracking servisi zaten [2026-02-25T00:31:09.282091][🔋: 55%] [BackgroundFetch] start success: 2
[2026-02-25T00:31:09.286111][🔋: 55%] ⚠️ [recoverPendingTravel] Cok eski (124 dk) yarim kalan yolculuk bulundu, tamamlaniyor...
[2026-02-25T00:31:09.287596][🔋: 55%] * [ActivityChange] Erken surus baslatma: in_vehicle (100%)
[2026-02-25T00:31:09.294200][🔋: 55%] ⏭️ [endTravel] Zaten tamamlaniyor, atlandi.
0 sayaci baslatiliyor...
...
[2026-02-25T00:31:09.301745][🔋: 55%] * Surus basladi..
[2026-02-25T00:31:09.667997][🔋: 55%] ✅* Yolculuk basariyla kaydedildi: {id: 22515}
en kontrol edilebilir.
[2026-02-25T00:31:09.668393][🔋: 55%] ✅ [Kurtarma] Yolculuk tamamlandi ve konumlar temizlendi.
atildi...
[2026-02-25T00:31:12.131474][🔋: 55%] NOTIFICATION | _onMotionChange: _isMoving: true
[2026-02-25T00:31:12.132956][🔋: 55%] * [processLocation] Speed: 7.5 km/h, Driving: false, Timer: false
[2026-02-25T00:31:12.144289][🔋: 55%] * [processLocation] Speed: 7.5 km/h, Driving: false, Timer: false
[2026-02-25T00:31:12.155989][🔋: 55%] * [processLocation] Speed: 7.5 km/h, Driving: false, Timer: false
[2026-02-25T00:31:12.776143][🔋: 55%] ✅ Kullanicilar guncellendi.
[2026-02-25T00:31:52.052733][🔋: 55%] * [processLocation] Speed: 24.3 km/h, Driving: false, Timer: false
[2026-02-25T00:31:52.062525][🔋: 55%] * Surus basladi..
[2026-02-25T00:31:52.453732][🔋: 55%] * [Headless] Konum gonderildi (speed: 24.3 km/h)
[2026-02-25T00:31:58.028639][🔋: 55%] * [processLocation] Speed: 36.6 km/h, Driving: true, Timer: false
[2026-02-25T00:31:58.420760][🔋: 55%] * [Headless] Konum gonderildi (speed: 36.6 km/h)
[2026-02-25T00:32:05.734192][🔋: 55%] [activitychange] - [ActivityChangeEvent still (33%)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions