ocetnik / react-native-background-timer

Emit event periodically (even when app is in the background)
MIT License
1.62k stars 230 forks source link

Background timer stops when the phone is locked and screen is off [iOS] #69

Open AmyNgithub opened 6 years ago

AmyNgithub commented 6 years ago

Background timer stops when the iPhone is locked and screen is off. However if the iPhone is locked, but the screen is on (showing lock screen and encouraging the user to press home button to unlock) background timer runs.

I have read similar issues however they mostly say that the background timer stops when the phone is locked. Ex: #15.

Anyone have any clues on how to solve this?

maslianok commented 6 years ago

Yeah, the same for me...

domozy87 commented 6 years ago

Yes, same issue

tahir-zahid commented 6 years ago

Yes, same for IOS..

skb1129 commented 6 years ago

Any workarounds for this?

bportman commented 6 years ago

The recent commit changing setTimeout to this.setTimeout in the backgroundClockMethod() function seems to have helped matters but not completely solved the problem. I have this issue but the background event runs for several minutes after the iPhone screen is turned off. It then stops. I'm digging in to try to solve this ASAP. Anybody else looking into this at the moment?

bportman commented 6 years ago

I was able to use this workaround to get my background timer running in the background non-stop even with the phone locked and screen off: https://github.com/ocetnik/react-native-background-timer/issues/9#issuecomment-291562476

bportman commented 6 years ago

That was a bad solution - the timer stops after 3 minutes if the user plays audio in another app. Still hunting for something that works without the "silent audio hack".

mattelianyc commented 6 years ago

i find all of this wildly upsetting. I've been working on a bluetooth proximity app. I'd like to continue reading RSSI values frequently while the phone screen is off. Is there really no way to perform frequent background polling??

bportman commented 6 years ago

From my investigations it's more possible on Android, but iOS there is not a way to guarantee a background process persists permanently. Even with playing a silent audio in the background it will eventually put the process to sleep on some if not all devices. The actual behavior varies depending on device, OS, and settings. I was able to get to an acceptable place using a combination of this package and react-native-background-geolocation because that package has the ability to wake up the background process when a significant location change occurs. I'm still looking for ways to further enhance it so the process never goes to sleep, and I'm coming to the conclusion it may not be possible.

mattelianyc commented 6 years ago

yeaaaa I'm starting to realize the same. Maybe I can wake the device with a message from the BLE peripheral. Out of curiosity, were you able to get accepted into the iOS App Store using the geolocation package for purposes other than intended?

bportman commented 6 years ago

The only thing they gave me a hard time about was background audio. They said nothing the first two versions I submitted, but for the 3rd version they kept rejecting it. I was able to get them to call me and convinced them to approve it just for one more version, but if I need to publish again it will be to the volume purchasing program, which is the proper place for business distribution. I'm told they will be less strict there about approving background modes. So if your app is for a business use you may consider going straight there instead of trying to get into the public app store.

mattelianyc commented 6 years ago

Gotcha. Thanks for detailing this out for me. I’ve read elsewhere about people having success with prompting notifications from the peripheral device rather than polling for data from the central, iOS device. I’ll have to try my luck there... Thanks for the feedback !! On Fri, Oct 5, 2018 at 3:17 PM bportman notifications@github.com wrote:

The only thing they gave me a hard time about was background audio. They said nothing the first two versions I submitted, but for the 3rd version they kept rejecting it. I was able to get them to call me and convinced them to approve it just for one more version, but if I need to publish again it will be to the volume purchasing program, which is the proper place for business distribution. I'm told they will be less strict there about approving background modes. So if your app is for a business use you may consider going straight there instead of trying to get into the public app store.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocetnik/react-native-background-timer/issues/69#issuecomment-427471790, or mute the thread https://github.com/notifications/unsubscribe-auth/AfpQ189laL1OI7Su9A0X_mH8rTDpSksUks5uh7BLgaJpZM4RjIPV .

shafiqshams commented 6 years ago

Not working

User2004 commented 5 years ago

https://webappcodes.com/how-to-use-nstimer-background-in-swift

Use above link for use Timer in background

User2004 commented 5 years ago

Any workarounds for this?

https://webappcodes.com/how-to-use-nstimer-background-in-swift

Please try with this link

mttirpan commented 5 years ago

Any workarounds for this?

https://webappcodes.com/how-to-use-nstimer-background-in-swift

Please try with this link

Please guide me, how can I use ?

bmp123 commented 4 years ago

Same issue

Ramin-Khodaie commented 1 year ago

same issue in android