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

[Bug]: onGeofence not triggered for initial geofence entry on iOS after fresh install #1452

Open
2 of 3 tasks
Jonny1987 opened this issue Mar 19, 2025 · 0 comments
Open
2 of 3 tasks
Labels
bug Something isn't working

Comments

@Jonny1987
Copy link

Required Reading

  • Confirmed

Plugin Version

4.16.9

Flutter Doctor

[✓] Flutter (Channel stable, 3.27.1, on macOS 14.7.2 23H311 darwin-arm64, locale en-US)
    • Flutter version 3.27.1 on channel stable at /Users/user271021/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (3 months ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.98.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.106.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.7.2 23H311 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.7.2 23H311 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 132.0.6834.111

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

iPhone 8

Device operating-systems(s)

iOS 16.7.10

What happened?

After a fresh install, both start() and startGeofences() do not trigger onGeofence on iOS (when geofenceInitialTriggerEntry = true) when the user is in the geofence. However, an EXIT even still occurs when leaving the geofence.

Subsequent calls to start() or startGeofences() do trigger onGeofence though.

This was tested with a real device outside.

Plugin Code and/or Config

bg.Config(
  desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
  distanceFilter: 10.0,
  stopOnTerminate: false,
  startOnBoot: true,
  debug: true,
  enableHeadless: true,
  logLevel: bg.Config.LOG_LEVEL_VERBOSE,
  geofenceModeHighAccuracy: true,
  notification: bg.Notification(
    title: 'Background location tracking',
    text:
        'This ensures you will be automatically checked-out when you leave',
    smallIcon: 'drawable/ic_notification',
    color: '#18B09C',
    sticky: true,
  ),
)

// This is how I start the tracking
final now = DateTime.now();
final start = DateTime(now.year, now.month, now.day);
final end = now.add(Duration(minutes: minutesUntilExpires));
final scheduleStr =
    '${DateFormat('yyyy-MM-dd HH:mm').format(start)}-${DateFormat('HH:mm').format(end)}';

final config = bg.Config(
  schedule: [scheduleStr],
);

await bg.BackgroundGeolocation.stopSchedule();
await bg.BackgroundGeolocation.setConfig(config);
await bg.BackgroundGeolocation.removeGeofences();
await bg.BackgroundGeolocation.addGeofence(
  bg.Geofence(
    identifier: venue.id.toString(),
    // radius slightly larger than radius when fetching venues to ensure we avoid
    // potential issue of checkin button appearing when we are outside the geofence radius
    // which will cause no EXIT event to be triggered when user leaves (since we need to have an ENTER
    // event first)
    radius: geofenceFetchRadiusMeters + 10,
    latitude: venue.lat,
    longitude: venue.long,
    notifyOnEntry: true,
    notifyOnExit: true,
  ),
);
bg.BackgroundGeolocation.start();
bg.BackgroundGeolocation.startSchedule();

Relevant log output

@Jonny1987 Jonny1987 added the bug Something isn't working label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant