Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is background tasks the solution for this problem?

I need to develop an enterprise app that monitors the network traffic. Basically it detects if the user is in wi-fi or cellular data and save the amount of bytes was sent and received in a period of time. I saw an App at the AppStore that do exactly this job. Detecting wi-fi or cellular data is quite simple using the Reachability Sample provided by Apple. My problem is to keep monitoring the bytes sent and received while the app is in background.

As it is an enterprise App, I used UIBackgroundModes "voip" to avoid the app to be terminated. I also installed the setKeepAliveTimeout method and I'm able to see the logs each 10 minutes, BUT only for 10 seconds after the method runs. I mean, setKeepAliveTimeout brings my App to run a Timer for 10 seconds each 1o minutes.

I'm thinking wether or not a task in background is the best solution for my problem.

I'll appreciate any comments.

EDIT: Ok guys. Thats the perfect way to do it.

First of all you must read this: http://www.christian-fries.de/blog/files/tag-ios.html

I tried this and it works really fine. All we need to do is to create a second thread detached from the main one. This way we have a continuos threading running forever. You must see the GCD docs at Apple's website also.

Second thing you should consider for an enterprise App is to set it up as a voip App, this way iOS will put your App running even after a reboot. It's a special behavior iOS has to keep voip Apps running.

Thats it guys. I hope it can help you.

like image 682
Trinca Avatar asked Dec 03 '10 19:12

Trinca


People also ask

What does it mean task host is stopping background tasks?

It might also say "Task Host is stopping background tasks," which means you have to either wait for it to finish or close it manually.

Why is it necessary to put into the background long running processes?

TL;DR: Android apps use the main thread to handle UI updates and operations (like user input). Running long-running operations on the main thread can lead to app freezes, unresponsiveness and thus, poor user experience. To mitigate this, long-running operations should be run in the background.

What is the current recommended way to handle long running background task?

Recommended solutionScheduling deferred work through WorkManager is the best way to handle tasks that don't need to run immediately but which ought to remain scheduled when the app closes or the device restarts.


1 Answers

We dont have access to this data. There is no way to measure traffic.

The app you saw made an estimation (eg. 1mb/min) and after applicationWillEnterForeground. then you calc time x estimated-traffic and there we go.

Unfortunately there is no way to measure, so I did a traffic-reset in settings and then i streamed exactly 1 min music. after a few repetitions I had my results. The problem is, that this works only fine with static traffic-processes like audio or video.

hope could help endo

EDIT: look answer below!

like image 196
endo.anaconda Avatar answered Oct 13 '22 00:10

endo.anaconda