I'm developing an application with SWIFT, which sends the location of cars through a REST call. When the application goes to background after 7 minutes, the loop that is sending the location stops being sent.
Does anyone know of any way to keep the loop running?
In the documentation it informs that this is a normal behavior .. but it needs to continue making this call of REST.
You may need to enable "iOS background data transfer". Check here an article on this topic: https://topologyeyewear.github.io/engineering-blog/2017/11/20/background_transfer/
Good luck!
Related
Hi i have to create a service in IOS OS that sends data like current location details,battery level,and other info every 15 min to the server via post api ,I understand it will not work once app is removed from app stack forcefully.But can i do something so that service will run ,background until app is killed forcefully.I know we can do only some work in background modes.Can i do someway around so that my app service always run in background
Use NSTimer and call that method which contains API call, Hope this solves your problem.
I am sure, your problem is might be solve by Apple push Kit. For this you have to need a back-end service. Generally ApplePushKit used for the VOIP(Internet calling and video call).
You have need to do following thing.
1) You have to Fire Notification every 15 Min(Pushkit notification not shown by user because it is silent never show to user).
2) You have receive controll in PKPushRegistry in method
3) You have received controll for the executed code for 30-40 second
4) Call Your API during the this time.
I have a custom framework which the client app can consume. I want the framework API's to run even when the application enters the background. How can I achieve this?
Thanks in advance.
It depends on what your app is doing after entering the background.
Perhaps you are looking for UIBackgroundTask. You can take a look at the method beginBackgroundTaskWithExpirationHandler: of UIApplication.
This method lets your app continue to run for a period of time after it transitions to the background. You should call this method at times where leaving a task unfinished might be detrimental to your app’s user experience. For example, your app could call this method to ensure that had enough time to transfer an important file to a remote server or at least attempt to make the transfer and note any errors. You should not use this method simply to keep your app running after it moves to the background.
Background execution on iOS is a very advanced topic.
Without any details, all I can do is forward you to the official Apple documentation.
This explains ALL possible modes that allow your app to run in background.
I've spent a lot of time looking at the options but am still not 100% clear, so wanted to reach out for some guidance.
Scenario is this:
User submits an HTTPS request to our backend server for some data via an iOS app
Depending on the data, the first (only) request can take a REALLY long time. like, say, 10+ minutes (shocking i know)
When that payload finally does become available and is returned via the HTTPS request, we then want to use it to update the UI in background.
The assumption here is that the user has moved on to another app whilst waiting for the data to arrive (and lets also assume they haven't killed the app).
Is it possible to handle this via iOS 8+ API's without the app being force/killed by Apple when in the background ?
Could we use background task for example?
var backgroundTask: UIBackgroundTaskIdentifier
xxx.beginBackgroundTaskWithName...
etc
Before testing some code blocks we just wanted to see if someone has (a) already done this and/or (b) whether we're heading in the right direction
Thanks for your help.
You should re-think on your web service which may take almost 10 min to process. If you are not able to optimize server task processing time then below one of the idea may be help you.
You can divided your one request into multiple request to reduce processing time and get response in faster way.
Your server should sent notification to app when its done with its task. So app will came to know task is done.
I am not sure why you try to update UI when apps in background mode , you may try to update UI when users come to foreground mode from background mode.
Please check this link which show as example of long running task. Where its use a blank audio play to keep alive app background task.
You can used "Background fetch" functionality.
For learning purpose you can refer this link
I'm writing a iOS/Swift application which reads data from a REST service each X minutes and updates the UI accordingly.
Now I would like that when the app is put in the background, a task keeps being invoked at X minutes intervals reading from the REST service and, in case the data just read satisfies a given condition, show a notification prompting the user to bring the app back to the foreground.
In my searches I've read that during applicationDidEnterBackground event, I should start a task with beginBackgroundTaskWithExpirationHandler.
The problem is that, if I've understood correctly, this allows a maximum of 10/15 minutes after which the app is terminated if the task is not stopped with endBackgroundUpdateTask, while I want the task to keep polling the service indefinitely (at least until the user disable it from the app's settings)
My question is:
How is this kind of functionality performed normally? Do some common solutions or best practices exist for the solution of such a problem?
Use iOS Background Fetch feature where you can specify minimum background fetch interval. But actual interval between successive invocation of your code will be determined by iOS framework. For details checkout this link: http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520
I use this approach in my app and I think it is a preferred way of doing.
You can use a local notification that can be presented from the background in case your condition is met.
Correct, iOS will eventually shut down the background process, you can't enforce continuous background activity. Use the backgroundTimeRemaining property to check how much time your application has left and try to handle it as gracefully as possible by calling endBackgroundTask so that iOS does not force kill your app.
As a solution, you could think about using remote notifications with with content-available : YES, which runs the didReceiveRemoteNotification
Have a look at the Parse.com Their local datastore is an abstraction for what you are trying to acheive.
By the way, is it really necessary to refresh in the background. If call is relatively quick, there is no need to refresh until the user open's the app. Background processes like that, using the net can be quite battery consuming when the user are not on a Wifi. So consider the use case carefully!
I am looking for something that is equivalent to Services in Android. As far as I have searched I haven't found anything useful. I found Background Fetch but according to my understanding it cannot be used long processes.
Here is what I want to use it for.
fetch a list of twitter user ids from our web server then auto-follow those usernames in background. As there are limits in Twitter API, so the process will be long possibly 3-4 hours. Is this possible on iOS?
There is no long-running background mode for continuous execution of apps in iOS.
This doesn't really sound like the right task for a mobile device. Running a 3-4 hour background job would be bad for battery life.
You can implement the function on a server somewhere and use push notification to send updates to the device.
An Android Service use case that is often cited is a background music service, which I have implemented as an exercise. It is not a given that a long running task actually will consume a lot of battery. Rather, it appears Apple is guaranteeing that such an event cannot happen through API design.