Required Reading
Plugin Version
5.2.0
Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.38.9, on macOS 26.5 25F71 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)
Device Manufacturer(s) and Model(s)
iPhones
Device operating-systems(s)
iOS18+
What happened?
"NSInternalInconsistencyException - Unsupported value for standard codec"
The app crashes unexpectedly while it is closed and the background service is running, and TSLocation is listed as the cause in all of these crashes.
Plugin Code and/or Config
static Future<void> configure(TrackingService service, int userId, String gsm,
String countryCode) async {
bg.BackgroundGeolocation.onLocation(
service.onLocation, service.onLocationError);
bg.BackgroundGeolocation.onMotionChange(service.onMotionChange);
bg.BackgroundGeolocation.onActivityChange(service.onActivityChange);
bg.BackgroundGeolocation.onProviderChange(service.onProviderChange);
bg.BackgroundGeolocation.onHttp(service.onHttp);
bg.BackgroundGeolocation.onConnectivityChange(service.onConnectivityChange);
bg.BackgroundGeolocation.onHeartbeat(service.onHeartbeat);
bg.BackgroundGeolocation.onGeofence(service.onGeofence);
bg.BackgroundGeolocation.onSchedule(service.onSchedule);
bg.BackgroundGeolocation.onPowerSaveChange(service.onPowerSaveChange);
bg.BackgroundGeolocation.onEnabledChange(service.onEnabledChange);
bg.BackgroundGeolocation.onNotificationAction(service.onNotificationAction);
final l10n = AppLocalizations.of(ContextUtility.context!)!;
await bg.BackgroundGeolocation.ready(bg.Config(
debug: false,
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: l10n.tracking_notification_title,
text: l10n.tracking_notification_text,
),
),
// 2. Geolocation ve Filtreleme Seçenekleri
geolocation: bg.GeoConfig(
desiredAccuracy: bg.DesiredAccuracy.medium, // Batarya optimizasyonu için medium kullanıldı
locationUpdateInterval: 30000, // Batarya tasarrufu için 30 saniyeye çekildi
fastestLocationUpdateInterval: 15000, // 15 saniyeye çekildi
deferTime: 10000, // 0'dan 10000'e çekildi (Batarya için kritik)
geofenceModeHighAccuracy: false, // true'dan false'a çekildi (Geofence GPS sömürüsünü durdurur)
distanceFilter: getSafeDistanceFilter(service),
stopTimeout: 15,
// iOS'ta 25 metre çok küçük olduğu için GPS'i sürekli uyanık tutuyor.
// iOS için 100m, Android için 50m yaparak cihazın "Stationary" (Sabit) modda kalma süresini uzatıyoruz.
stationaryRadius: Platform.isIOS ? 100 : 50,
elasticityMultiplier: Platform.isAndroid ? 2.0 : 1.0,
geofenceInitialTriggerEntry: true,
geofenceProximityRadius: 1000,
// iOS: sistem arka planda konumu duraklatabilsin (pil ekranındaki "arka plan" süresi ve gereksiz GPS).
pausesLocationUpdatesAutomatically: Platform.isIOS,
// iOS'ta automotiveNavigation pil tüketimi en yüksek moddur. Eğer hareket yoksa sistemin uyumasına izin verir.
activityType: bg.ActivityType.automotiveNavigation,
showsBackgroundLocationIndicator: true),
geofenceModeHighAccuracy: false,
// 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": l10n.tracking_bg_alert_title_not_enabled,
"titleWhenOff": l10n.tracking_bg_alert_title_off,
"instructions": l10n.tracking_bg_alert_instructions,
"cancelButton": l10n.tracking_bg_alert_cancel,
"settingsButton": l10n.tracking_bg_alert_settings
},
activity: const bg.ActivityConfig(
activityRecognitionInterval: 10000, // 5000'den 10000'e çekildi
minimumActivityRecognitionConfidence: 75, // 50'den 75'e çekildi
disableStopDetection: false,
),
// Üst Seviye Kontrol Parametreleri
reset: true,
isMoving: true,
allowIdenticalLocations: true,
enableTimestampMeta: true,
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,
),
)).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
Required Reading
Plugin Version
5.2.0
Flutter Doctor
Mobile operating-system(s)
Device Manufacturer(s) and Model(s)
iPhones
Device operating-systems(s)
iOS18+
What happened?
"NSInternalInconsistencyException - Unsupported value for standard codec"
The app crashes unexpectedly while it is closed and the background service is running, and TSLocation is listed as the cause in all of these crashes.
Plugin Code and/or Config
Relevant log output