paleksandrs / APScheduledLocationManager

MIT License
84 stars 19 forks source link

Timers not working if device is locked #14

Open alpennec opened 7 years ago

alpennec commented 7 years ago

Hello,

I tried to use this solution in a demo application. It works fine when I put the app in background, but as soon as I lock the device, I notice that the timers are not fired anymore at regular and defined interval. If I specify a time of 60 seconds, and I lock the device, the app is checking for a new location with a random duration between 5 and 15 minutes.

If I play a fake sound in background, the app behaves as expected and the timers correctly fire and restart the location manager. But I don't want to use this hacky solution...

Any idea why the timer is not running when device is locked?

Thanks, Axel

paleksandrs commented 7 years ago

Hi! If you set acceptableLocationAccuracy high and the location manager is not able to retrieve the location with the desired accuracy it will keep on trying. That is the only reason I can find why you keep getting inconsistent intervals.

alpennec commented 7 years ago

Hi,

Thanks for your answer. I tried to set an acceptableLocationAccuracy very high (1000m) to see if this was working as expected.

Have you tested it on your side, on a real device?

Thanks Axel

paleksandrs commented 7 years ago

Yes I have. I just tested on iPhone running iOS 10.3.1. Not sure what to recommend

alpennec commented 7 years ago

And it is working correctly on your side? Just with the example you provided in you repo?

On 26 June 2017 at 13:33, Aleksandrs Proskurins notifications@github.com wrote:

Yes I have. I just tested on iPhone running iOS 10.3.1. Not sure what to recommend

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/paleksandrs/APScheduledLocationManager/issues/14#issuecomment-311034081, or mute the thread https://github.com/notifications/unsubscribe-auth/AB_HZvcMZLKmhb3PWZZbUcIxdPM1p1viks5sH5bugaJpZM4OErwi .

paleksandrs commented 7 years ago

Yes it does. Try to debug it. See if waitTimerEvent function is triggered, check if acceptableLocationAccuracyRetrieved returns true

alpennec commented 7 years ago

I just tried again with your project (I have customised it a bit for my use). I think the reason why I get inconsistent timers is because my device is in Low Power Mode. Can you try on your side? I also use Silent Push to wake up my app, same conclusion: if my device is in Low Power Mode, silent push are not received by the device.

carlhung commented 7 years ago

it happens to me. I have come for seeking solution. i set the acceptableLocationAccuracy with in 1000m as well. when the phone is on(unlocked), the location updates regularly. when the phone is locked(screen is off), the location updates like 5-10 mins each time. and I haven't set to low power mode.

alpennec commented 7 years ago

Have you tried with Low Power Mode disabled?

When enabled, it does not work because a lot of services are delayed or disabled (background app refresh for example).

Axel Le Pennec

On 10 Jul 2017, at 20:19, carlhung notifications@github.com wrote:

it happens to me. I have come for seeking solution. i set the acceptableLocationAccuracy with in 1000m as well. when the phone is on(unlocked), the location updates regularly. when the phone is locked(screen is off), the location updates like 5-10 mins each time.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlhung commented 7 years ago

I mean I haven't turned on low power mode, never. but it still happens to me.

carlhung commented 7 years ago

when you test the device, you should unplug it and lock your device. you will see. if i plug the cable in. the method will work regularly even you have turned off the screen.

raviAggarwal61 commented 7 years ago

@alpennec @carlhung @paleksandrs were you guys able to find any solution for this?

carlhung commented 7 years ago

@raviAggarwal61 still, no.

paleksandrs commented 7 years ago

@raviAggarwal61 solution for what exactly? For Low Power Mode?

raviAggarwal61 commented 7 years ago

@paleksandrs this problem occurs without low power mode too, in the locked state. This works fine when the device is connected to XCode and logs are printed but as soon as you unplug the device and repeat the locked state testing, updates stop completely, no matter what accuracy or distance filter.

Also, can you please explain this line perform(#selector(stopAndResetBgTaskIfNeeded), with: nil, afterDelay: 1), why we need to do this? As I was experimenting to understand, I changed the delay to 0.5 and 2 seconds, in both cases it stopped working. Struggling to understand, why is this working (only in background unlocked state) only for the 1-second delay.

paleksandrs commented 7 years ago

@raviAggarwal61 can you reproduce this issue on the sample app that is provided without any modifications? If yes, what iOS version, device are you using, please provide detailed step by step guide. Also, have you configure your Xcode project by enabling Background Modes (Location updates)?

raviAggarwal61 commented 7 years ago

@paleksandrs yeah, this issue comes in sample app too, let me give you the steps.

  1. Install the app from XCode.
  2. Disconnect the phone from mac and relaunch the app.
  3. After 1-2 updates put the app in the background and lock the phone.
  4. Unlock the phone and check the app after some time, you'll see no updates were recorded in the time when the phone was locked.

PS: Although if you do not lock the phone and simply put the app in the background, everything works fine.

I am using iPhone 6 iOS 10.3.3 and background modes are configured for location updates. Attaching screenshot for reference.

img_0058

Update: I checked it on some iOS versions and it seems to be working on iOS 9.3 but isn't working on 10.3.2, 10.3.3 and 11 beta. So probably something changed after iOS 10?

carlhung commented 7 years ago

@raviAggarwal61 you said: this problem occurs without low power mode too, in the locked state. This works fine when the device is connected to XCode and logs are printed but as soon as you unplug the device and repeat the locked state testing, updates stop completely, no matter what accuracy or distance filter.

this is exactly happening on me.

carlhung commented 7 years ago

@raviAggarwal61 i also tried slient notifications to kick my app to update. about first 1x slient notifications the device will get, afterward, you can't get any slient notifications for about 20 mins. then you will get again. I think the APN server can't accept too many notifications which will be thought as spam messages.

paleksandrs commented 7 years ago

@raviAggarwal61 you are right. I retested and it seems that something has changed starting from iOS 10.3. I tested it on iOS 10.2 as well and everything worked. So I believe something has changed since 10.3 release. Not sure what solution could be at this moment.

carlhung commented 7 years ago

I tested on iOS 11. I think it works again.

magtimmermans commented 7 years ago

I have tested on ios 11. Also not working when device get locked. In unlock state and background seems to work fine. But n the moment the device locks it will not work anymore. Any suggestions? Improvements of the code?

protspace commented 6 years ago

ios 11.1 works as expected while locked and not in debug mode and not connected with cable

janvi12 commented 6 years ago

In my case location update stops when screen lock. so whats the solution for this? I want location every 30 seconds.

hang321 commented 6 years ago

AlexGee17 fix works for me on iOS 11.4, location updated even when screen locked. parameter set as every 60 seconds and accuracy 10000.