GPS Location Updates Every X Minutes EVEN IF APP TERMINATED - ios

I was reading the following two forum posts about getting a user's location every X minutes:
Getting user location every n minutes after app goes to background
How do I get a background location update every n minutes in my iOS application?
But then I realized this only works if the app is in background mode. (And the point of it being so the OS doesn't ever suspend or terminate it for inactivity, to take back some system resources, but correct me if I'm wrong).
But is there a way to wake up a terminated app every X minutes to get a GPS location?
I know you can subscribe to significant location changes, but those are only if the user moves more than 500m... and has no concept of time (every X minutes).

Related

Get CMMotionActivityManager updated when app is terminated

Right now I'm developing an app that needs to know what the user is doing activity-wise (standing still, running, walking, ect.) all the time. I found that using CMMotionActivity might be a good way to do this.
Except for one thing: when the app is terminated, the CMMotionActivityManager stops running. First I tried to solve this by creating a cronjob to send remote silent notifications every n minutes and wake the app for motion data. I then did some research and found that silent notifications do not wake the app.
After some more research, I found that using Location and startMonitoringSignificantLocationChanges the app will be woken from a terminated state when the user moves 500 meters or more.
However, I believe I need more data then one point every 500 meters. Something more along the lines of one point every 5 minutes would be nice. But the sense I get is that startMonitoringSignificantLocationChanges won't update even if the user stands still for a whole day.
So my question in a nutshell is two parts:
Am I misunderstanding startMonitoringSignificantLocationChanges? Will it give me a notification every so often even if the user doesn't move?
If I don't misunderstand significant changes, is there any way to get Motion Updates every n minutes even when the app is terminated?
Thanks friends.

Can I get location every 5 seconds after app is killed or terminated?

I want to get user current location every 5 seconds, after app gets killed or terminated.
Is there any way I can achieve that?
I have tried
[locationManager startMonitoringSignificantLocationChanges]
but it only works when I move more than 500 meters or after 5 minutes.
I have also tried Background Task Identifier
UIBackgroundTaskIdentifier
but when I killed app then it is not working.
I have tried almost everything available but none of them are working.
Can I get current location using Silent Remote Notifications, because I have read it somewhere.

iOS Location - Significant Location Change in iOS 8/9 can start standard location service?

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)

Waking up an app from background by a time interval?

is it possible on newest ios to make a tracking app wake up every x minutes in order to send the stored locations to an url, even if the user is not moving?
Requested functions of the app are:
App is getting locations based on distance filter (example: only get coordinate via gps, when user has moved more than 10 meters.
App is not allowed to send every new position immediately to url
App should store all new locations of the last 3 minutes
App should send stored positions (of the last 3 minutes) in an interval of 3 minutes. (! Even if user has not moved since a while, app shall connect to url.
App is mainly running in backround.
Example case:
User has moved more than 10 meters at 9:00:11 to position 53.432, 13.245, at 9:01:20 to position 53.235, 13.435 and at 9:03:10 to position 54.002, 13.768. No more movement of more than 10 meters before 9:15:00.
So from 9:00:00 until 9:15:00 device has located 3 coordinates.
Order from server is: Send all locations in an interval of 3 min., starting from 9:00:00.
Requested result is:
At 9:03:00 app sends all positions from 9:00:00 until 9:03:00:
9:00:11: 53.432, 13.245,
9:01:20: 53.235, 13.435
At 9:06:00 app sends all positions from 9:03:00 until 9:06:00:
9:03:10: 54.002, 13.768
At 9:09:00 app sends all positions from 9:06:00 until 9:09:00:
„no new positions“....
Problem is:
App has to be waken up, in order to process actions like sending informations to the server.
One event, that could wake up the app would be a movement of more than 10 meters.
But since user is not moving from 9:03:10 until 9:15:00, there is no event that wakes up the app. App stays suspended and will not send the location of 9:03:10 before next movement at 9:15:00
Solution?
Are there other possibilities to make the app wake up and send stored locations at 9:06:00?
Can apps have an internal timer to wake up?
(According to my understanding a timer app is not waking up, when the alert sound should be given. Instead it is scheduling a local notification to fire at the time of the alert.)
But if it is possible to schedule local notifications, can´t an app schedule other actions like „wake me up“?
Thanks a lot for your time and help!
the app can attempt to run background tasks, but it can't force itself to stay in existence - the OS will shut it down after a couple of minutes, regardless of local timer handlers or notifications.
Your best bet is that as soon as the user has moved more than 10 metres, the server starts sending push notifications. You can have a handler which can wake the app in the background, and you can use this handler to send data back to the server.
There are a lot of rules regarding when to use certain background modes, so in case you haven't come across it before, check out this link.
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

How to tackle an app that fires recurring local notifications but on a changing schedule?

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.

Resources