I've read plenty of times that we only can run background tasks for location, voip and audio.
Well, I just noticed that in Windows Phone there is a possibility to set up a background agent that starts every 30 minutes and runs for X seconds, then it's killed.
Is there any kind of agent in iOS?
I need to upload location every 30 mins. However, if I use significant location changes, if I'm at home for the weekend and my app is closed, it won't upload any location until I go out.
So, how would you do this?
Thank you!
There is nothing of this kind. But what is wrong with not uploading the location when it didn't change?
Related
I am writing a Xamarin application that needs to download and upload data on a schedule.
Currently the task is working fine on Android by using the Android Foreground Service along with the Notification Manager. https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services
BUT in IOS...
I can't figure out how to get a background service to stay running on a schedule (every 10 minutes) when the application is pushed to the background or the screen is off.
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/
I can't use the Background Fetch because it runs when it feels like running and I need to run on a strict 10 minute schedule.
I can't use the Background Transfer Service because it only "starts" by the Background Fetch which is back to not running every 10 minutes.
I can't use the Remote Notifications because the app is doing the "push" to the service and not the other way around.
Since I am gathering GPS data, I tried to use the IOS GPS Location Manager Service but that only works if the device physically moves inside a 10 minute window and some of the devices do not move every 10 minutes YET we still want data from the device.
I tried to use a Background Task with the Expiration Handler but it dies after 5 minutes.
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/ios-backgrounding-with-tasks
Any suggestions are greatly appreciated.
Assumes that I registered "location updates" service. If the location changes significantly, the callback function gets invoked.
Question: How long is my function allowed to run in the background? Let's say the function does so much work and need 10 minutes to finish, will it be terminated by system?
I guess Apple won't allow long-run job in location-updates-callback. But I couldn't find the official explanation. Could anyone help? thanks a lot.
https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Your app will receive location updates till it stays in background. There's a chance that your app would go inactive when other active apps require memory. In this case, your app will stop receiving location updates. There's no fixed background execution time mentioned anywhere in Apple's documentation. It may be possible that your app can receive location updates for more than 10 minutes but only if it stays in background.
Many questions concerning iOS Location tracking have been asked on here, but recently Apple has updated much of their functionality and so many of the answers are obsolete, my question is specifically targeting iOS 8 and 9.
I am interested in creating a location tracking application which will accurately track the user even when the app is closed. To do this, apple states:
If you leave the significant-change location service running and your
iOS app is subsequently suspended or terminated, the service
automatically wakes up your app when new location data arrives. At
wake-up time, the app is put into the background and you are given a
small amount of time (around 10 seconds) to manually restart location
services and process the location data.
So my understanding is, if you have all of the necesarry permission and plist keys present, the OS will wake up your app and allow you to do something for 10 seconds, or if it needs more time it can:
If an iOS app needs more time to process the location data, it can
request more background execution time using the
beginBackgroundTaskWithName:expirationHandler: method of the
UIApplication class.
Now, this says that if my app needs more time to process the location data, it may start a background task (with an expirationHandler) to handle that. When reading about background tasks, I read that background tasks can run for a maximum of 10 minutes
So my overall question is, when my app gets woken up when a significant location change has occurred, is it possible to start the standard location service and have it run in the background indefinitely? Is it possible to start another background task before the first one expires?
EDIT:
From the Apple Documentation it says:
because it wakes the system and your app at least every 15 minutes,
even if no location changes have occurred, and it runs continuously
until you stop it
So my idea is, if the user starts their phone from nothing and never opens the app, after at most 15 minutes (even if they are standing still), the OS will fire my app, in which case I could start a background process that I can start the GPS tracking in, and thus getting accurate GPS location. Would this logic work with the OS?
The main problem is that significant location changes cannot be used for
"accurately track" the user.
Significant means 1000m, since it is cell tower based, and not GPS based.
So your app is woke up when the user moves into the next GSM cell.
This is not acurate enough for acurate tracking.
finally this means you cannot acuratley track when the app is closed, this works only in running app or background running up.
"When reading about background tasks, I read that background tasks can
run for a maximum of 10 minutes"
No, thats not true. My app runs in background and records GPS locations until the battery is drained (8h+). (It does not use the significant location mode)
I'm creating an app that needs to fire local notifications for sunrise and sunset on a daily basis.
Sunrise and sunset times changes every day.
I want the registering of the local notifications to take place even if the user didn't open the app (i.e. a background task). So the user installs the app, sets his location (since sunrise and susnet calculations are location based) and then he knows he'll get notifications for sunrise and set every day without needing to open the app or being connected to the internet.
Ideally I need a background task for registering local notifications over a given period which runs at least once every period. "e.g. registers local notifications for the next week, which in that case I need it to run at least once a week".
None of the current background modes fit my case, I tried a background fetch, but since there're no data downloaded iOS stopped running my background task after a couple of days
I know I can use push notifications, but I don't want to unless it's my last option, cause I want the notification to take place even if the phone was not connected to the internet.
So how do you think I can tackle this? Is there something I'm missing?
Get Location for every ānā minutes in background. By Using beginBackgroundTaskWithExpirationHandler and NSTimer .it keeps app live in background.
So, You can schedule a localnotification in background.
For getting location update in background Refer the link
How do I get a background location update every n minutes in my iOS application?
(From iOS7 finite-length background task time reduced to 180 seconds. so you must fetch location within next 180 seconds.)
If user force quit the app. the app destroyed all the task . Use Significant location change or region monitoring to restart the Background task and get location for every ānā minutes.
Apple has provided certain services which can run in the background for 10 minutes, but what if I have to perform some other task like downloading a file ... how much time limit do I get for it
Before iOS 7 you could request up to 10 minutes of background time (via beginBackgroundTaskWithExpirationHandler:) or you could use any of the background modes available at the time (such as location, voip, etc).
VoIP handler, for instance, will be called at most every 10 minutes and will give up to 3 minutes of background time IIRC.
With iOS 7 you can download and upload files out-of-process, without your app running. Please check documentation on NSURLSession and NSURLSessionConfiguration.
You can do it (directly after your app went to the background, that is, not let's say an hour later), and you approx. do have 10 minutes, although that is not guaranteed. See here in the apple documentation:
https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
You can request a Executing a Finite-Length Task in the Background
which will run in background for maximum 10 min. This should be long enough to download file.
So no it is not just for certain services, you can get your app running the background for a longer period of time if your app is a VOIP app, track user location, playing audio or your app is app for an external accessories.