icapps / flutter-background-location-tracker

Flutter background location tracker plugin. (Android / iOS)
MIT License
31 stars 37 forks source link

Release build is not receiving location updates in dart. #38

Closed shahmirzali49 closed 2 years ago

shahmirzali49 commented 2 years ago

It's working when the app is in the foreground, but when I close the app, not updating.

by the way, I got the always permission. there is no problem with permissions

vanlooverenkoen commented 2 years ago

can you provide us with the smalles example possible where it is not working? Did you try the example project?

shahmirzali49 commented 2 years ago

background_example.zip

Yes, this is the example project. first I get LocationWhenInUse permission after Always, and then in the foreground is working. but when the app is killed not work.

thank you for replying and helping.

shahmirzali49 commented 2 years ago

@vanlooverenkoen I tried real device (iphone 8 ios 15.5) and used your example project codes. unfortunately I don't have logs. but say me If you need something and how , I can provide you.

vanlooverenkoen commented 2 years ago

We created local notification to debug the background location tracking. That way you are 100% sure if it is working or not. Could you try that.

vanlooverenkoen commented 2 years ago

@Shahmirzali-Huseynov I have updated the example project in #40 . maybe you did not change the distance filter. (I forgot to change that as well, but after setting that to null I got updates every x seconds. while connected to my PC)

shahmirzali49 commented 2 years ago

@vanlooverenkoen you mean If I define distanceFilterMeters to null it will work?

vanlooverenkoen commented 2 years ago

I am not sure how you are testing. But the distanceFilterMeters are set to 5. so If you don't move more than 5m you will not get any updates.

shahmirzali49 commented 2 years ago

I tried your #40 example project. this function didn't affect. is it working for you?

final result = await Permission.locationAlways.request();

vanlooverenkoen commented 2 years ago

What do you mean by killed? Completely removed from the resent apps? Or just send to the background. Because if you force quit the app from recents apple will kill all services and background services linked to your app

shahmirzali49 commented 2 years ago

@vanlooverenkoen no generally, I run release #40 , on iPhone 8 real device, and just click the request location permission button, and nothing happens.

vanlooverenkoen commented 2 years ago

Let me double check that today.

vanlooverenkoen commented 2 years ago

I forgot to add:

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        'PERMISSION_LOCATION=1',

The pr is updated

shahmirzali49 commented 2 years ago

@vanlooverenkoen Did you test example #40 in release run on real device IOS ? because when I run the app in debug mode location tracking is working (when the app is alive, not background or when is killed), but when I release run, location tracking not working even app isn't killed or on background/foreground. request permission working but tracking not working completely(run release).

vanlooverenkoen commented 2 years ago

Hmm you could also run on simulator and select bikeride for example. But in my case everything is working fine. Did you set your permissions to always allow

shahmirzali49 commented 2 years ago

@vanlooverenkoen I mean in Release mode completely not working location tracking, even app is alive.

shahmirzali49 commented 2 years ago

Can you test release mode on Real device IOS? when it's possible

shahmirzali49 commented 2 years ago

@vanlooverenkoen I test also in the simulator. city run/biker too. but same when the app is killed it's not working

https://user-images.githubusercontent.com/49102327/189109266-4b920efa-bc4e-43aa-b991-47aa689ccecc.mp4

vanlooverenkoen commented 2 years ago

That is normal.

What do you mean by killed? Completely removed from the resent apps? Or just send to the background. Because if you force quit the app from recents apple will kill all services and background services linked to your app

Can you test by just closing the app but not killing the app. That should work normally.

vanlooverenkoen commented 2 years ago

I will also test on a real device. Thanks already for your feedback!! Much appreciated!

shahmirzali49 commented 2 years ago

On the foreground/background, it's working. When the app is killed not work. but it's all in debug mode. In release mode completely nothing working unfortunately :/.

thank you for the package, your effort, and your support of the community.

vanlooverenkoen commented 2 years ago

Alright yes. killed state that is to be expected. That is an OS limitation.

I will check the release mode later today or tomorrow.

vanlooverenkoen commented 2 years ago

Indeed I am not receiving anything in release. That is strange. Let me investigate. Thing is we are using this (before #40) in production in 2 apps where it is work just fine. So that is strange.

vanlooverenkoen commented 2 years ago

When I go to the background I do see the blue pill in the status bar which indicates that the app is using location in the background. I saw the blue pill for a second right after you killed the app. And then it disappeared. (as expected)

shahmirzali49 commented 2 years ago

Yes, location permission is working, but Tracking is not. I think Blue pill means the app has always location permission and be attention the app can track or track your location.

vanlooverenkoen commented 2 years ago

No blue pill actually means that is tracking in the background. Which it is doing. We are just doing something wrong when trying to contact the dart implementation

If you open your console. on mac you can see the extra logs to debug the native part.

image
vanlooverenkoen commented 2 years ago

https://github.com/icapps/flutter-background-location-tracker/blob/f127ee393888ec0a36b325b737808ed79806a515/ios/Classes/SwiftBackgroundLocationTrackerPlugin.swift#L134

You can see here what is happening. I will investigate this. And fix this major issue with #40 🙈

shahmirzali49 commented 2 years ago

Okay, thank you for your effort. I will wait :)

vanlooverenkoen commented 2 years ago
Runner  14:46:07.056512+0200    [VERBOSE-2:dart_isolate.cc(668)] Could not resolve main entrypoint function.
Runner  14:46:07.056672+0200    [VERBOSE-2:dart_isolate.cc(167)] Could not run the run main Dart entrypoint.
Runner  14:46:07.057252+0200    [VERBOSE-2:runtime_controller.cc(385)] Could not create root isolate.
Runner  14:46:07.057945+0200    [VERBOSE-2:shell.cc(604)] Could not launch engine with configuration.

Maybe it is the same issue as we had on Android: long instead of int. but we are already using a Int64 in swift

vanlooverenkoen commented 2 years ago

Very weird that it does work ik debug on a real device. But not in release on a real device. 🤯

shahmirzali49 commented 2 years ago

yes exactly, 🥲😔

vanlooverenkoen commented 2 years ago

I am getting the same error in release on Android. 🤯 It seems to be a flutter issue. because it is working perfectly in debug

vanlooverenkoen commented 2 years ago

I think I found it!! There was a bug related to this. (https://github.com/flutter/flutter/issues/91841#issuecomment-1006026551)

I found that I had to add the @pramga('vm:entry-point') to make it work in release

@pragma('vm:entry-point')
void backgroundCallback() {
  BackgroundLocationTrackerManager.handleBackgroundUpdated(
    (data) async => Repo().update(data),
  );
}
vanlooverenkoen commented 2 years ago

@Shahmirzali-Huseynov is it possible to test again?

shahmirzali49 commented 2 years ago

Yeah, after adding @pragma('vm:entry-point') it works. sorry for the delay. If you want, you can close the issue.

vanlooverenkoen commented 2 years ago

I will be fixing the comments on my pull request. and after that, I will close it.