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

[iOS] Doesn't work on app killed #54

Closed
martofeld opened this issue May 2, 2020 · 26 comments
Closed

[iOS] Doesn't work on app killed #54

martofeld opened this issue May 2, 2020 · 26 comments
Labels
bug Something isn't working

Comments

@martofeld
Copy link
Contributor

I downloaded the project and tested it against the provided example app. I installed it in a real iOS device and started it. Started getting a few sparse location, went to background and the project didn't show any notification but still got a few updates. As soon as you kill the app it stops.

Other info:
Had to get some work done according to the iOS migration guide to get it to work with XCode 11

Tested with
iPhone XR - 13.4.1

@mehdok
Copy link
Collaborator

mehdok commented May 3, 2020

There is no need for notification on iOS.

The idea for iOS is that when app is killed and new location received the os should wake the app and execute some code and then kill the app again. After this if you open the app you should see that locations is saved. If it's not the behavior you get there might be a bug;

@martofeld
Copy link
Contributor Author

I believe it's not the behavior, I left the app killed for hours and haven't gotten any new locations, at least none that are saved via the FileManager. I've been testing mostly using the example app provided in this repo.

Might be related but given that we are in quarantine I haven't moved much this past few days. As far as I understand this uses the significant location API from Apple.

@pkuzco
Copy link

pkuzco commented May 4, 2020

I tested both on an emulator and a real device. doesn't work on either.

I found one issue in this code:
https://github.com/rekab-app/background_locator/blob/master/ios/Classes/BackgroundLocatorPlugin.m#L93

I think you should call startMonitoringSignificantLocationChanges again before returning from didFinishLaunchingWithOptions, but I doubt this is the only issue that causes this feature not to work.

This plugin seems to have a complete implementation, but I haven't tested that:
https://github.com/rmtmckenzie/flutter-plugins/blob/master/packages/location_background/ios/Classes/LocationBackgroundPlugin.m#L32-L60

@martofeld
Copy link
Contributor Author

@pkuzco I took a look at the one you sent but doesn't seem to be working. It crashes in background when the location is updated. I've been working on trying to integrate their code in this plugin but unfortunately my iOS is not strong enough.

@mehdok mehdok added the bug Something isn't working label May 5, 2020
@martofeld
Copy link
Contributor Author

@mehdok Do you happen to have any ETAs on fixing this bug? This is the best library I've found so far for background location but this bug renders it unusable in iOS

@alexlopespereira
Copy link

alexlopespereira commented May 6, 2020

@mehdok I'm on a similar situation that @martofeld is on. I might have to migrate to another plugin because I can not use this plugin on iOS.

@mehdok
Copy link
Collaborator

mehdok commented May 6, 2020

@martofeld @alexlopespereira I'm trying my best to fix this bug a.s.a.p . In the meaning while any PR or suggestions are very welcome.

@martofeld
Copy link
Contributor Author

@mehdok that is great news!! I would love to help but unfortunately iOS is not my strong suite. I did test the plug-in that was linked earlier in the comments and it does seem to work.

@martofeld martofeld changed the title [iOS] Doesn't create notification and doesn't work on app killed [iOS] Doesn't work on app killed May 6, 2020
@ellie
Copy link

ellie commented May 8, 2020

I'll check this out! I have some experience with location tracking stuff on iOS, and I kinda really need this functionality haha

@martofeld
Copy link
Contributor Author

@elliebike @mehdok I've been thinking a lot about this lately. As far as I can tell, the only Location operations you can do while the app is in background is significantChangesMonitoring which would mean your app gets restarted to let you know the users location (but only every 500m).

I also read that the CLLocationManager can do Region Monitoring (geofencing?) and I'm not sure if that will ran while the app is killed, but if it were to run it would be a great possibility to obtain locations over smaller distance changes. It would probably require to unregister the old location and register a new Region based of the last location every time we get a new event.

Does any of you think that is something feasible?

@martofeld
Copy link
Contributor Author

Created #59 as a possible fix following my previous comment

@mohamnag
Copy link

18 Days, a PR ready to go but no feedback :-(

@neetable-chollarasan
Copy link

neetable-chollarasan commented Jun 8, 2020

any update on this. still, I am not getting the location after an app killed

@mehdok
Copy link
Collaborator

mehdok commented Jun 9, 2020

@chollarasan There is a little problem with mentioned PR that need to be addressed before merging.

@MazEbeid
Copy link

This is by far one of the most complete and useful plugins out there - but iOS background location updates are quite important - are you making progress on this front? @mehdok

@travisjayday
Copy link

Any updates on this? Did the PR ever get merged to fix this? I'd love to help too because I kinda really need iOS background location updates but I'm a noob when it comes to native iOS. Does it work yet?

@mehdok
Copy link
Collaborator

mehdok commented Jul 19, 2020

@MazEbeid @travisjayday The mentioned PR is merged and the problem should be solved in the latest version. Please Test last version and let me know if you have any problem.

@travisjayday
Copy link

Thanks @mehdok, will test and report back.

@travisjayday
Copy link

Yay it's working AFAICT! Even after the app is killed on iOS. Also managed to get Firebase/Firestore working in the callback, so that's awesome! Thanks for your amazing work guys 👍

@mehdok mehdok closed this as completed Aug 17, 2020
@zgosalvez
Copy link

@mehdok / @travisjayday, how were you able to verify? I don't think iOS is launching the app in the background after quitting the app. But I can confirm the plugin works if the app is running/background.

@mehdok
Copy link
Collaborator

mehdok commented Dec 12, 2020

@zgosalvez
You can set the callback to write new locations to shared preferences, then after you kill the app and relaunch it you can see that there are some locations that received when the app was killed;

Besides this, you can see a small arrow in the status bar whenever a new location is coming;

@zgosalvez
Copy link

@mehdok, I'll try that. Right now I'm using Console to see if the process is relaunched but it doesn't look like it. I can confirm tho that it subscribe to region monitoring via the logs.

Client ... is subscribing to notification kCLConnectionMessageRegionMonitoring

I set my distanceFilter to 1.0 in hopes of getting a log/local notification just by moving around the house. Or should I move farther? The weird thing is, I don't actually have to move when the app is running to get a log/local notification from my callback.

@mehdok
Copy link
Collaborator

mehdok commented Dec 12, 2020

1-meter distance filter is pretty good, iOS is really accurate in this case;

The weird thing is, I don't actually have to move when the app is running to get a log/local notification from my callback.

I'm not sure, but I think iOS will try to conserve energy at least when your app is terminated, so it is normal that you receive less location update in that case;

@jbxbergdev
Copy link

jbxbergdev commented Oct 12, 2021

@mehdok I read through this thread and am still not quite sure as how to handle the app being killed by the iOS system correctly. As far as I understand, some further actions are required for iOS? Can you (or somebody else on here) please explain these steps, or even better, add them to the plugin docs?

@jbxbergdev
Copy link

jbxbergdev commented Oct 12, 2021

Yay it's working AFAICT! Even after the app is killed on iOS. Also managed to get Firebase/Firestore working in the callback, so that's awesome! Thanks for your amazing work guys 👍

@travisjayday can you please explain how you got Firebase working in the callback, in the case the app was killed? Thanks.

@insoon0930
Copy link

@mehdok i just found out that latest version(1.6.6) example doesn't work in IOS when app is killed... (it works in android perfectly) Reading this issue, seems like you guys solved it, but is there anything else i need to do to use it? I'm confused because it doesn't work...

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