3

I did search on the internet, found some people who have the same problem but no one did get any solution yet... So I hope anyone here is the G I am searching for..

1 - I did enable "Location updates" and "background fetch" in Background Modes.

enter image description here

2 - I did call locationManager.startMonitoringSignificantLocationChanges() on the right place, I checked this on the way I write and string into my Firebase Database when the app will be waked up after terminating.

3 - I am checking on the right way if there is a location key in launchOptions just like Apple on their documentation, see:

https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app

enter image description here

So why is my launchOptions nil? I cannot understand why this happens... Because the App is getting waked up, the mistake cannot be on my locationManager handling..

I found this on stackoverflow but my launchOptions are nil so the code is not getting inside the if... Location update even when app is killed/terminated

Please help.

Priyal
  • 879
  • 1
  • 9
  • 30
alarsut
  • 41
  • 4
  • Hi, did you find a solution for this? I am having the same issue – iqra Jun 06 '21 at 15:05
  • @aledap I notised, that my application was started from background when moving, so it does work but my launch options are always null, so I did save with user defaults a value and by starting I check if this value is true, and run some code depending on this, but this only works because I do only have one reason why it starts from background, if you have more than one, it would be harder to know why the app has been started... – alarsut Jun 07 '21 at 16:33

1 Answers1

0

It look like you don't save change in database.
Add log and check what happen.
Database file can be locked if device is locked with passcode. And it can happen with SignificantLocationChanges. I hope it link help you - IOS app unable to access files in background when screen locked with passcode

P.S. Also for startMonitoringSignificantLocationChanges() you don't need enable "Location updates", it need for startUpdatingLocation()
startMonitoringSignificantLocationChanges needs background location enabled?

UPD: https://developer.apple.com/documentation/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati

If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. In such a case, the options dictionary passed to the application(:willFinishLaunchingWithOptions:) and application(:didFinishLaunchingWithOptions:) methods of your app delegate contains the key location to indicate that your app was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.

location should have in youre launchOptions, i recommend just print launchOption in console. And see it with (viewable from XCode -> Devices -> {your device} ), what keys are present?

Eysner
  • 584
  • 4
  • 15
  • Thank you, but I don‘t know what you mean, to write into the database works perfectly, just the locationKey Is Not being set when the app wakes up into background mode. And I did read, that this key only will be inside the dictionary if the check box of background modes for location updates is enabled. If I am missunderstanding something, please let me know. The first line where I put "wokeUp" into my database, is working. Only the if, where I want to create an list with all keys, is failing because there is no key in launchOptions. – alarsut Jan 10 '20 at 11:18
  • @alarsut i recommend just print launchOption in console. And see it with (viewable from XCode -> Devices -> {your device} ), what keys are present? – Eysner Jan 13 '20 at 05:25
  • Could you please contact me? Just write me an email to kochhilfeaticlouddotcom with your skypename or anything you have. I do not getting this working. Logs are not showing and launchOptions are nil. I will add the solution, if we get one, under my post as update marked... – alarsut Jan 19 '20 at 19:27