Prevent phone from going to sleep - react-native

So, I'm developing an app that has a timer for about 5 minutes. During this time, the app should remain active. Accessing geolocation, counting steps, etc. The problem I'm facing is that the app falls asleep and the timer stops ticking.
I'm using react-native-background-timer for a timer. It shouldn't fall asleep, but it does. On both, android and ios. Actually it works perfectly fine when the app is in debug mode. But on release version without debug app simply falls asleep after about 3 minutes when the screen is turned off and timer stops ticking. It resumes when phone wakes up.
I can keep screen on all the time, with react-native-keep-awake, but I don't like this solution. Because my app also counts steps, and the phone should be ideally in the pocket. And with active screen, it will register accidental presses. Not good.
There should be a way. Phone calls can be really long with disabled screen and phone app doesn't sleep. I just don't know which direction to take. It's also hard to test, because with debug mode, app doesn't fall asleep at all. I need to run the release version and wait 3 minutes hoping the timer won't asleep.
Any ideas? Thanks.

Related

iBeacon entry.exit callback when app is force killed by swipe up iOS

I read in many places that if user swipes up and kills an app, that app will not be able to receive location updates. I get didEnterRegion and didExitRegion callbacks are received when my app is not killed and is in background. But if I swipe kill app, app doesn't get those callbacks. My question here is,
Is it that app will stop getting callbacks ever? i.e., even if the app is launched again and is in background it does not get the callbacks
I read about startMonitoringSignificantLocationChanges and background app refresh when used together, I can get callback even when app is killed by swipe. I tried this and could not get it working. Is this the expected behavior?
Will startMonitoringSignificantLocationChanges and background app refresh together when used, I get region entry/exit callbacks after rebooting device?
This is not expected behavior. You are supposed to get didEnterRegion and didExitRegion callbacks even after killing an app in the task switcher. If you are not seeing this, something may be wrong with your app or testing methodology. Posting code may be helpful.
A few caveats and tips:
Make sure your app has obtained backround permission with locationManager.requestAlwaysAuthorization(). Without it, it cannot detect at all in the background.
Detection in the killed state did not work on iOS 7.0.x. It started working as of 7.1+.
Make sure you wait long enough to get detections. In some app states, it can take up to 15 minutes.
Before killing your app in testing, check logs to ensure you know what CoreLocation thinks is your current region state. If you turn off a beacon then kill your app, CoreLocation may not have had time to realize the beacon disappeared, thinking it is still inside the region. If you then turn on the beacon, you will not get a new entry event because it thinks you are already inside.

Background Location Services after reboot in iOS 7

I'm interested in a border line iPhone app able to detect the user location continuosly.
The app will be delivered in enterprise mode (so no Apple approval).
Basically it should run forever (resetting the backgroundTimeRemaining through the location service start end stop).
the issue that I was not able to fix is to relaunch the app after a reboot, event if I declare the voip capability, it seems that the system give me only 3 minutes, no more time despite all the workarounds.
so actually I'd like to know if someone was able to implement this sort of behaviour on iOS7.
thanks in advances, please find below some references.
iPhone - Backgrounding to poll for events
to run app continuously in the background
Background Location Services not working in iOS 7
Start Location Manager in iOS 7 from background task
ok, I got it.
the music hack is the solution.
During the further 180s of background time a small mute playback of few seconds (of local mp3) restart the backgroundTimeRemaining counter.
bye

Is there a way to determine whether a Windows Store app is suspended?

I'm building a Windows Store app and it pops up toast notifications from time to time. I also have an animation that plays to show when something has updated. Both of these happen at the same time.
What I would like is to not show the toast when the app is running.
So, is there a nice easy way to determine this or do I have to manually track the state via the suspending/resuming events?
Edited info:
The solution has a background task project which goes off, gets the data, then decides if anything has changed that the user needs to know about.
If so, it creates a toast, updates the tile badge, and plays an animation to fade in the new data.
The issue is that I don't want to show the toast and update the tile badge if the user has the app full screen. Similarly, playing the animation isn't needed until the app is resumed (that's the easy part though).
I realize I could solve it by having one timer that works when the app is running, and a separate background task for when it's suspended but that seems like overkill in this case.
The simple answer here is that if your app is suspended, your code won't be running.
If you want to pop up toasts when your app is suspended, you'll either need to use the WPNS or a background task to track changes.

Android issues in wakelock?

Hai i developed a application using broadcast receiver.I need to wake my Application always.so i used wakelock.here my code
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
problem
1.If i wake up always my battery is getting drained.
2.if i cal w1.acquier() ,Is necessary to release the w1(ie w1.release)
I don't understand what is your 1st question.. I thought that is a fact if you want to keep waking up your application?
If keep your screen not dimming down is what you want to achieve, you could try this code:
//This is to keep the screen not dimming down.
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
Wake lock keeps the cpu running on your application even when the screen is off so it will drain your battery hard. You want to call release on your wake lock when you no longer need the application to keep running in the background (example not waiting for any more callbacks).

How do I play an alarm sound and present a custom view instead of just a notification?

I'm working on an alarm clock application for iOS 4.x. The other alarm clock applications that I've seen are able to present the user with something other than a local notification (i.e., a custom view) and are able to play a sound file. I've been looking into how that's done and have only found this solution:
Play sound with screen turned off / don't let iPhone go to sleep
Is there another approach or is this the best practice?
When your app is not visible, you can't display anything. The silent sound workaround is a cool trick but when a user presses your home button, your app is not visible (and might get destroyed under certain conditions) -> therefore you can't display anything.
So if you tell your user to use your alarm clock by firing it up and then press the sleep button it will work - you can display anything on your screen after the user unlocks the iphone again.
Needless to say that playing sound (even silent sound files) drains the battery so your user might be disappointed if he's not woken up because his iphone has run out of battery.
And yes, there is best practice: Local Notifications! Beginning with iOS 5 it will display your apps icon next to the notification...