I am working on a musical training game, which I'm using Unity 3D to create.
It fires out random notes.
Problem is, my android device has only five options for "time before screen goes off", and the longest of these is 10 minutes.
So after 10 minutes the screen goes off, and the app stops running.
How can I keep the app running beyond this 10 minute cut-off?
Is there any way I can override to turn the screen off after one minute (obviously while it continues to emit notes -- this would be a useful power saving feature) or keep the screen on indefinitely
Screen.sleepTimeout = (int)SleepTimeout.NeverSleep;
Application.runInBackground = true;
However, the documentation for Screen.sleepTimeout says that you can only set it to one of the two SleepTimeout presets (system default and never sleep).
Also Screen.sleepTimeout used to take a float, now it takes an integer, hence the typecast.
It does all seem bit of a mess, as these links will demonstrate:
http://forum.unity3d.com/threads/201359-How-to-gain-control-over-10-minute-screen-app-timeout?p=1363228
http://forum.unity3d.com/threads/117997-Screen-sleepTimeout-0-on-Android
http://answers.unity3d.com/questions/46204/stop-mobile-screens-turning-off.html
http://answers.unity3d.com/questions/403092/how-do-i-reset-screensleeptimeouts-user-input-time.html
When you turn off the screen the application goes into "onPause", then the OS is responsible for freeing memory automatically.
You need an android service
Related
I've been googling for a long time about how to run code in the background for IOS, and for what I have come up with the short answer is that you can't. And the long answer that you can but is limited. I've seen similar apps to the one I am creating so I feel like there should be a way to make it.
So on to the actual app I want to create. I want to create an application that will continuously play a random sound from a list in between a set interval, let's say for this example 30-60 seconds. So randomly every 30<t<60 seconds a sound should play. You can think of it as a positive affirmations app that should play positive affirmations throughout the day. I've seen such apps exist for IOS, I haven't tried them but I assume they should work like that? And when the app is firing the code to play the sound, Ideally I also want it to send information to a server.
I am using "Flutter Background Service" and "AudioPlayer" packages and have gotten a very very early demo version to work on android where it plays the sound after a random amount of time. And now I want it to work for Iphones also. Since it's not a playlist, I can't use the inbuilt functions for IOS that allows media players to run in the background. For what I can understand is that no code can run for longer then 30 seconds on IOS from when the app goes to the background, or the screen locks. And you can't run background tasks more often then every 15 minutes, or 3 minutes for small work. But that is way to long for the use case I want. I'd want to be able to run the function every 10 seconds to maybe 1 minute at the latest.
So I am wondering, is there a way to get such an application to work for IOS? It feels like it should be possible somehow. I don't really care if you have to "play dirty" to achieve it, and I don't know if it matters or not but I am not planning on publishing the app to the app store. It will only be a private app for me and a few friends.
One way I've been thinking about is maybe use push notifications from a server to trigger it. But I'd rather not have to resort to this if I can help it, if it even is possible to have a push notification to run code/trigger functions in the background?
I would like to know if there are limitations regarding how often I can execute something in the background. I found this library : background fetch and it says that on the iOS part I cannot execute it more often than 15 minutes.
Are there workarounds for this?
My purpose is to check in the background the available Bluetooth devices detected and to send them to a database.
I only have experience in android and I'm not sure how to convert it to iOS or if it is possible.
Yes, there are limitations imposed by iOS. It will decide when your app is given time to execute background tasks such as a fetch of web data. It can be more frequent than 15 minutes but on average it may be every 20 minutes at best. It might be two hours or more. We are not privy to the algorithm and cannot predict the result.
Known factors are power state, how well your app conforms to the rules and gets its work done in the time allotted, and some measure of how (and when) the user uses your app. Low battery? Fewer background tasks allowed. User never uses the app before 8AM? Few fetches called overnight. It's all beyond developer control.
A developer can use a timer to trigger a routine task but it's only relevant if the app stays active in the foreground.
I have an app that does geofencing/beacon region monitoring. The app functions well in - foreground, background and killed state.
The problem: I have been noticing a delay in the beacon/geofence events(entry/exit) after I restart the phone(without killing the app) and do not launch the app manually upon restart. I only start getting the entry/exit events after 3-4 minutes of restart, even if I enter the region before.
Is it normal behaviour?
Thanks
This is normal. I have noticed this delay of several minutes since CoreLocation added iBeacon support in version 7. The exact amount of time varies from one hardware model to the next, and even between reboots on the same hardware model.
While it might be possible to statistically characterize the delay with repeated tests, this is very time consuming to do. In the end, there is nothing you can do about it anyway.
I've developed app which should process some data every 15 min. So I added voip flag into plist file. And use setKeepAliveTimeout with 900 sec(15 min). Also added background task functionality which processes some data.
Processing of data takes up to 10 seconds.
The problem is that app wakes up NOT in time. Sometimes after 12 min, sometimes after 16 min etc. But I need exactly in 15 min.
How to solve the following problem?
iOS version is 5.0+
If it's iOS's specific please provide me official reference into the apple's api document where this mentioned .
setKeepAliveTimeout:handler: is not a general purpose interval scheduler. It allows you to set the maximum interval between invocations of the supplied handler. The purpose of the function is to help you keep your connections from timing out or falling behind your VOIP applications standards (for things like online/away status).
So the first parameter (timeout) tells iOS to call your handler in no more than 15 minutes. If the OS decides that it's got some cycles to spare at 12 minutes, it might call your handler. Or in 7 minutes, or 15.
If you need finer grained control of the interval, you should set a smaller timeout window and just ignore invocations that aren't important to you. But the invocations will still going be fairly irregular.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setKeepAliveTimeout:handler:
In general, there is currently no way to make it wake your app on a precise schedule. You must adhere to iOS' limited background processing options, all of which are designed to give the OS a lot of leeway to manage overall priorities and resource needs across ALL processes.
I'm currently developing an app where the device's location should be send to a server. I've worked through the MSDN articles on the background agents and accessing the location. This works so far. My location is transmitted to the server when I've triggered a location change which is farther away than the set MovementThreshold.
However, I've read that testing of background agents can be complicated. If you use the Emulator, you can easily change your device's location very often. But on a real phone, location background services are limited in their idle runtime to 30 minutes and execution of commands should only take up to 25 seconds. Background agents can also be disabled by the user from the phone's settings screen. They are also deactivated, when the agent crashes more than two times in a row. Another limitation is that inactive background agents are stopped after 4 hours, if they don't update an apps live tile.
My app updates a live tiles counter, so I think my background agent should be running up to 14 days without restart from my app. I've tested the app from yesterday to today and saw the background agent running (when looked up from the settings). There was also the small dot in the upper bar visible, indicating that a programm is accessing the phones geo location. However, sometimes the dot vanishes and my background agent is killed for no obvious reasons.
Therefore my question are:
How can I reliable test geo location on a real device without the need to travel with phone and attached debugging laptop?
How can I test in a timely manner for the timeout scenarios I've mentioned (30 min, 4hrs, 14 days)?
How can I check for these two crashs of the background agent?
I think I've made some missinterpretations of how WP8 defines Background Agents. The new WP8 background agent for location is only active, when the app is running. This means that the app must not be closed with the back button. However, it can be switched to the home screen with the windows button or with a long hold back button to access other apps from multitasking.
Regarding my questions:
How can I reliable test geo location on a real device without the need to travel with phone and attached debugging laptop?
How can I test in a timely manner for the timeout scenarios I've mentioned (30 min, 4hrs, 14 days)?
I still have no suitable solution. You are somewhat limited to testing with real devices and the necessary time required to test your constraints.
How can I check for these two crashs of the background agent?
I don't know how to check for this programmatically. It may be, that a user can see this crashing app as a blocked app in the list of background tasks of the phone's setting. There should be a way to detect a blocked app from this list with the help from the links I've supplied above.
For my project, I needed a location background agent, which runs even with locked screen or with no open app. Therefore I've used a PeriodicAgent to require the location once every 30 minutes so that I can send it to the server. But be aware that this background agents cannot access your application settings or classes (see Communication between foreground app and background agent).