This is a long awaited article that I promised to write. A couple months ago, I found a way to get the location update from iOS 7 and 8 even when the app is not active on foreground and not in the background. Yes, you may get the GPS coordinates from the iOS devices even when the app is killed/terminated either by the user or the iOS itself.
Apple does not communicate much with the developers on the ways to do that. If you remember this post from early 2014: Apple’s iOS 7.1 will fix a geolocation bug — after developer sends letter to Tim Cook. In iOS 7.0, Apple prevents the location update when the app is killed/terminated/suspended. But, Apple has fixed the “bug” starting from iOS 7.1 by allowing the app to get the location coordinates.
I have read the release notes for iOS 7.1 but I couldn’t find any information related to location updates and also the way to get the location when the mobile application is terminated/killed/suspended. The iOS 7.0 to iOS 7.1 API Differences for CoreLocation is stated as “No changes“. What?!
But, I didn’t give up in finding the solution. So for a few months, I used my free time to play a bit of the iOS APIs including the CoreLocation APIs. After many months of trials and errors, I finally found the solution.
I will provide the full solution, upload to the Github and write the detailed information on this post.
How to get Location Update for iOS 7 and 8 even When the App is Killed/Terminated
I have written an old article related to getting the continuous Background Location Updates for iOS 7 and iOS 8.
The method to get the location in the background continuously for iOS 7 and 8 is using the method “start Updating Location”
[my Location Manager start Updating Location];
and then the next trick would be on the delegate method “didUpdate Locations“. You will have to use a timer and handle the Background Task appropriately. Any missing steps and the location will not be updated continuously.
But in the case of getting the location when the app is terminated/ suspended, I can not use [my Location Manager start Updating Location]; The only way to make it work is to use:-
[another LocationManager start Monitoring Significant Location Changes];
Surprised. Surprised. Yes, I only figured that out after many trials and errors.
Another important trick is, you will have to know how to handle the key “UIApplication LaunchOptions LocationKey” on the app delegate “didFinish Launching WithOptions“. Here is the sample code:-
– (BOOL) application: (UIApplication *) application didFinish Launching WithOptions: (NSDictionary *) launchOptions {
self. shareModel = [Location ShareModel sharedModel];
if ([ launchOptions objectForKey :UIApplication LaunchOptions LocationKey]) {
self. shareModel. anotherLocation Manager = [[ CLLocation Manager alloc]init];
self. shareModel. anotherLocation Manager .delegate = self;
self. shareModel. anotherLocation Manager .desiredAccuracy = kCLLocation AccuracyBest ForNavigation;
self. shareModel. anotherLocation Manager .activityType = CLActivityType Other Navigation;
if( IS_OS_8_OR_LATER) {
[self. shareModel. another LocationManager requestAlways Authorization];
}
[self. shareModel. another LocationManager startMonitoring Significant Location Changes];
}
return YES;
}
In addition to the didFinish Launching WithOptions method, I have created a location Manager Instance when the app is active. Here are some code examples:
– (void) application DidEnter Background: (UIApplication *) application
{
[self. shareModel. another LocationManager stopMonitoring Significant Location Changes];
if(IS_OS_8_OR_LATER) {
[self. shareModel. another LocationManager request Always Authorization];
}
[self. shareModel. another Location Manager start Monitoring Significant Location Changes];
}
– (void)application Did BecomeActive:( UIApplication *) application
{
if(self. shareModel. another Location Manager)
[self. shareModel. another Location Manager stop Monitoring Significant Location Changes];
self. shareModel. another LocationManager = [[CLLocation Manager alloc] init];
self. shareModel. another LocationManager .delegate = self;
self. shareModel. another LocationManager .desiredAccuracy = kCLLocation AccuracyBestFor Navigation;
self. shareModel. another LocationManager .activityType = CLActivityType OtherNavigation;
if( IS_OS_8_OR_LATER) {
[self. shareModel. another LocationManager requestAlways uthorization];
}
[self. shareModel. another LocationManager start Monitoring Significant LocationChanges];
}
What exactly is the LaunchOptions Key “UIApplication LaunchOptions LocationKey”?
UIApplication LaunchOptions Location Key is very important to get the location update even when the app is neither active nor in the background.
If you read its description from the XCode, it says: “The presence of this key indicates that the app was launched in response to an incoming location event”. What does it mean?
You may realize that when your app is launched for the First time, the App Delegate method “didFinish Launching WithOptions” will run once. If you put your app into the background and then launch the app again from the background. This app delegate method will not run again.
The method will only run again after you killed/ terminated the app by swiping up from the App Preview Screen and then relaunch from where your app is located.
If your app is a location based mobile application and you need the user’s location even the app is terminated/suspended, then there is another way to launch the app without the user interaction. The iOS will launch the app for you.
When your app delegate methods LaunchOptions contains the key UIApplication Launch Options LocationKey, it means that your app is launched by the iOS because there is a significant location changes. So, you will have to do something with the new location GPS coordinates return from the location manager.
If order to do so, you will have to create a new instance of location manager and you shall get the location coordinates from the method “didUpdate Locations“.
How Frequent is the Location Updates?
As per Developer Documentation: Core Location Documentation.
Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.
So, you could only expect the location update if the device moves over 500 meters and at most once in every 5 minutes.
From my own testing (I am driving around a lot! To test the Core Locaton API), I only get the location update about every 10 minutes.
Full Source Code for the Location Updates Even when the iOS mobile apps is Suspended/ Terminated/ Killed
In this source code, I have included the methods to save the location GPS coordinates into a PList file. The purpose of saving into a PList is to record the location coordinates, the iOS Application States and the way location Manager is created (Add From Resume or otherwise).
Here are some simple instructions on how to test this solution:-
1. Download the project from Git Hub.
2. Change to your own Bundle Identifier (If need to)
3. Connect your iPhone with your mac.
4. Launch the app into your iPhone.
5. Killed the app. (Double tap and remove the app from the App Preview)
6. Travel around with your iPhone for a few days.
7. Download iFunBox for Mac or any alternative that allows you to open the app and Read the PList from the “Documents” folder.
8. From the PLIst, you will see something like the screen shot below:-
When you see the key “UI ApplicationLaunch Options LocationKey” under “Resume“, it means that the iOS has relaunched the app after the devices has moving significantly from the last known location. If you create a new location Manager instance, you will get new location from delegate method “didUpdate Locations“.
Source Code: GitHub Source Code for Getting Location Updates for iOS 7 and 8 when the App is Killed/Terminated/Suspended
it is not working on ios 8…..have u tested it on ios 8 too???
if you are willing to use VOIP push see this link
its workin fine on ios 7…but cnt get locztion after terminating app on ios 8…pls rply soon…thanx..
hi,
Its working fine on ios 7,but on ios 8 app is not resuming after termination.In ios its working fine in forground and background but not after terminating the app.Please reply soon and thanx for the post 🙂 …
Hi, It should work on iOS 8 as well as I have asked a friend to help me test it a few weeks ago. Can you double confirm on this? I don’t have an iPhone with iOS 8 for testing right now, I only have iPod Touch (with iOS 8).
I have tested with iPod Touch Gen 5 (iOS 8). It works well. What surprised me was even it does not have 3G, it was able to get the location when I was driving.
So, you must be doing something wrong on your end.
hi @ricky , its very helpful for me .
I want to access the location everytime like didlocationchanges return the location , when app have been terminated.
But when i use start Monitoring Significant Location Changes it update after 500 meter travel , so i want to know is there any way to reduce and get the location like every 10 meter or every minutes
Hello @Ravi where you able to do accomplish that ? if yes can you please share ?
I can also confirm this works well on ioS8 (iphone 5c) though struggling a bit with coming up with a mechanism to start and stop. I can get the location updates to stop happening when switch is set but when I leave connected I can see in log view that the background tasks are still being triggered.
I think in a previous post Ricky you mentioned you implemented toggling the background updates on/off – any clues on how you did that?
Hi Nev,
Thanks for your confirmation. 😉 I think when we monitor the significant location changes, we do not really need to stop the location manager. The solution for the current post does not use any background task as well.
By “previous post”, you meant this article? It is different comparing with the current post.
If you really want to end all the backgroundTasks, use the instance method
end All BackgroundTasks. I just updated the solution on Github by adding “-(void) end AllBack groundTasks;” on the public API.
FYI, if you want to monitor significant location changes and also sometimes getting the user location updates in a specific time interval, you would need 2 different location Manager instances to do 2 different tasks (Monitor significant location changes versus getting location in the background).
hi,
it working fine when app is terminated but os is active with other tasks i.e. screen is not locked.But in sleep mode i.e. when screen is locked all the time app is not resuming back in ios 8.
Yes, that could be the reason as I never do a testing when the app is active/the screen is locked as I assume it would work. Have you tried to test that by driving for over 500 meters and over 10 minutes?
I am going to make a trial run (put the app in the background and locked the screen) and see how it goes on my iPhone 4S and iPod Touch Gen 5.
no actualy i said when app is terminated and os in sleep mode i.e screen locked.In background modes its working fine.Problem area is when its app is when you are doing nothing with your phone and simply travelling around.App do not resume in this case.
Actually, I still don’t quite get what you meant. Can you list down the cases like the examples below?
Case 1: App is terminated by the user after opening (Not in the background)
Status 1: Working fine.
Case 2: App is launched and then putting in the background, locked the screen. Driving around for over 30 minutes.
Status 2: Not Working, not able to get the location on the PList.
Please list down the cases as detailed as possible. Thanks.
Case 1: App is terminated by the user after opening (Not in the background)but user is using other apps or receiving calls etc.
Status 1: Working fine.
Case 2: App is terminated by the user after opening (Not in the background) and locked the screen. Driving around for over 30 minutes.
Status 2: Not Working, not able to get the location on the PList.
I am not talking about background the only case i am facing issue is after terminating and screen is locked.
Thanks for the info. “screen is locked” means that you will have to the Passcode is On and you will have to enter a passcode every time when you want to open your iPhone. Right?
I will test the app on locked screen when I have some free time.
yes passcode is on.
Ok. Thanks for the information. I will test on my devices and see if I am able to find a way to fix it. It will take a while as I am busy with other projects.
Hi Ricky !
First of all thanks for the great code I’ve found on this website(especially “Getting Location When Suspended” and “Background Location Update Programming for iOS 7 and iOS 8”).
I’ve got two comments on your code above:
1. You forget to add NSLocation Always Usage Description key into Info.plist which is necessary for using localization services, even significant change monitoring.
2. From Apple docs property “desired Accuracy” in CLLocation Manager is not used when monitoring significant location changes.
And one more time – thanks for great website 😉
Hi PRZEMYSŁAW,
I just downloaded the project from GitHub, the NSLocationAlwaysUsageDescription is there on the Location-Info.plist. Please double check.
Yes, “desiredAccuracy” might not be needed. I will remove that and fix the potential bug that PRASHANT mentioned when I am free.
No problem. 😉
I need a help, i have implemented the solution as per in this website. It works really well when the app is in the foreground as well as in the background.
But i am unable to make my app work if the user kills in the multitasking or terminate the app in the background. I have included the start Monitoring Significant Location Changes but it doesn’t work..Please help on this.
Even when the app is killed, it should work pretty well. You must be doing something wrong. The only thing that I am unsure is on the locked screen.
You have to help yourself by doing more testing on the solution.
HI,
Is region monitering also a solution for this??I think aaps like life 360 are tracking location by region monitering. Life 360 has implemented tracking perfectly on ios 8.Who they have implemented this??
You may take a look at this post: iOS region monitoring. I have implemented the region monitoring. But I didn’t test on that for quite a while. There might be some changes or problems that I don’t know yet.
Life360 has raised over $75 millions funding and it has over 75 employees. I believe there are at least 10 mobile apps developers. May be even more than 20.
If I am able to focus entirely on the location services APIs, I might be able to find the solution as good as Life360. The problem is I am working in a few projects at the same time. So, I don’t have much time to do R&D on the Core Location APIs. I will do that when I have free time.
please provide this region monitoring solution on github . thanx…
I think there are other people who share a more complete solution for Region Monitoring on Github, you just need to do more search.
I simply don’t have time to compile a complete solution and upload to github.
How about the battery drainage ?
Battery drainage for start Monitoring Significant Location Changes is definitely much lesser than start Updating Location. It is actually a better method.
Will there be any issue with the Apple approval with this implementation ?
It will not have problem passing through the Apple approval process as it is not a private API.
Just tested your code, great work! please fix the bug that prashant pointed out, been waiting for a while now 🙁
I don’t have time to fix the “bug” at the moment. I am not sure if it is a bug or it is designed that way.
How about help me do some testing with other popular apps such as Waze or Google Navigation and see if they will be working when it is on the locked screen as well and report back? Tahnks.
Thanks for your article. Iam trying to implement both start updating Location and start Monitoring Significant Location Changes in order to make the app to get the location when the app is foreground or background or killed. But I could nt. Please provide your suggestions .
You will have to have 2 different location Manager instances to handle these 2 different functions.
Hi Ricky,
Is there any way to stop location monitoring after user manually kills application? (from the task manager) Because it can be very annoying to see phone updating location all the time, even if app is terminated by user.
From one side, appWillTerminate should be called, and we can call for stopMonitoringSignificantLocationChanges. But it doesn’t work always. Have you thought about this by any chance?
I did some testings on application WillTerminate some time ago, it has never been called. I am not sure the exact reason. I just made a quick google search and I found this: article. You might need to add a key “UIApplication ExitsOnSuspend” on your PList.
If that would not help, may be the best you can do is whenever application: didFinishLaunching WithOptions receives the key “UIApplication LaunchOptions LocationKey”, just stop monitoring the location from there.
Thanks for your answer, Ricky. I have 1 more question for you, if you don’t mind.
After upgrading to Xcode 6 my application stop updating in background on IOS 7 devices. It works, but just not updating location when app is on background. When I’m using IOS 8 – it works like a charm. Did you have such kind of problems? Now I have Base SDK 8.1 and Deployment Target 7.1.
PS^ It happens in both cases – usual location updates and signification
Hm… that’s weird. If it happens on iOS 8, I believe it might due to a key that you have to add inside the PList. But for iOS 7, it should work as intended. I suggest you to recheck everything on that device with iOS 7.
Its working in life 360 when screen is locked.
Ok. Thanks for the info. When I am free, I will do more testings. See if I am able to come out with a solution. It will take a while.
Is it possible to make a server call to send the location details when the app is killed ?
Yes, it is possible. I have been doing that on the app that I am developing. Just send the coordinates to the server from locationManager: didUpdateLocations.
Hi,
Nice Post. Is this possible to update location information to server when app is killed?
Please respond me.
Hi
Can we fire a local notification when app is terminated by user or suspended by iOS (not immediately) and there’s a significant location change?
Sorry for late reply. I actually forgot about this comment.
As far as I know, I couldn’t get anything from the app delegate function “application WillTerminate” normally.
Only after adding the key “UIApplication ExitsOnSuspend” on PList, then only I will get a response from “application WillTerminate”. But be really carefully on this, if you read the apple document on the “UIApplication ExitsOnSuspend” key.
It says: The app should be terminated rather than moved to the background when it is quit. Apps linked against iOS SDK 4.0 or later can include this key and set its value to YES to prevent being automatically opted-in to background execution and app suspension. When the value of this key is YES, the app is terminated and purged from memory instead of moved to the background. If this key is not present, or is set to NO, the app moves to the background as usual.
See: Apple Documentation
I have tried on my app. When I am moving the app to the background (tapping on the home button), the iOS actually kills the app.
To answer your question: If your app does not need to run in the background, Yes. You may implement the key and schedule to run a Local Notification whenever the app is terminated. If not, I believe there is No way to do that.
For significant location change, Yes. Just follow the way I implement the key “UIApplication LaunchOptions LocationKey” on didFinish Launching WithOptions up there. You may schedule a Local Notification whenever the did FinishLaunching WithOptions contains the key “UIApplication LaunchOptions LocationKey”.
Hi,
Nice example. but i want to update location after every 1 minute then what changes i need to do in this example. please reply fast…
Thnaks.
You are not able to get the location update for every N minute if you want to use start Monitoring Significant Location Changes. You will only get the location update after the device is moving at least 500 meters and only once in every 5 minutes. My own test: Every 10 minutes.
If you want location update for every N minute, please read: background location update
thanks…
Hi,
I checked link which you given. But in that after kill or suspend application, location is not update. i want to update location also after kill or suspend application. any suggestion?
If you want to get the location update after the app is killed/suspended, you can only use [location Manager start Monitoring Significant Location Changes], using this solution, you will not be able to get the location every N minute as it is the iOS that determines when to give you the location. The iOS will only return the location when the device has move for over 500 meters from the last known location and it will return the location at most once in every 5 minutes. Due to that, this solution will save some battery.
If you want to get the location every N Minute, you can only use
[locationManager start Updating Location], but when the app is killed, you will not be able to get the location.
If you want to have both getting the location for every N minute and also get the location even when the app is killed/ suspended, you will need to have 2 different location Manager instances to handle these 2 different functions.
The complexity to use 2 location manager instances at the same time is at another level.
Hi! I need to have both solutions but I’m very confused, how can i use 2 location manager instances?
I follow your tutorial using Monitoring Significant Location Changes and works perfect. Now, if I want to get the location every N Minute how can i manage 2 locations manager instances? Maybe with another @property (strong,nonatomic) LocationShareModel * shareModel called shareModel2? Or I need to create another class LocationShareModel.h and LocationShareModel.m?
Thanks
Hi Kepa,
I might not want to share the solution for having 2 instances of location manager working at the same time because I want to protect the my personal/company intellectual property.
I believe there are more than 1 way to use 2 different instances of location manager at the same time. The one that works well for my app might not work well for yours.
The 2 location services, that I shared on Github, have given you more than enough hints on how to do it. You just need to spend some time to do some experiments and combine these 2 solutions. I believe you will be able figure out a way to do that.
Hi Ricky!
I implementing a solution combining your two tutorials. I created two LocationShareModel. One that I am using for start Monitoring Significant Location Changes and another one for startUpdatingLocation.
It seems that they work properly, but I discovered something surprising. The location update for every N minute in background works perfect. The amazing thing happens when the app is closed, when the Significant Location Changes is triggered for first time, the location update for every N minute begins to run again every N minute with the app closed. I can understand but its working perfect.
is this the expected behavior?
Thanks
Hi Kepa,
Congrats. I think you have implemented successfully. 😉
But to be sure, you will have to run more testings and collect more data. You might face a certain situation where it is not working well. Then you might have to find a solution to fix that situation.
I detect that when the app comes to background from foreground the first update location callback is no calling stop Location Delay BySeconds after 10 seconds. Is this normal?
hi Kepa shall i need to create two instances in single share model or two share models.
hi,
can we get location always with region monitoring as we are getting in significant change?have u found anty solution for that locked screen issue in ios 8??
The region monitoring works differently compare with Monitoring Significant Location Changes.
For Region Monitoring, the app will only wake up when the device is crossing or leaving the regions that the app has monitored. On the other hand, if the app is monitoring significant location changes, the app will wake up when the device is moving at least 500 meters from the last know location (with at most 1 update for every 5 minute).
Nope. I don’t have time to do the R&D on the locked screen issue yet. It will take a while. May be 1-2 months.
Hi
I tested you solution and it is working fine thanks!
Quick question:
From your experience, do you think it would be possible to grab more then one hi-res location update after waking from a significant location update?
( I need to determine if i’m approaching a target at a certain speed)
When the device is moving more than 500 meters from the last known location, you should get the location update. The location that you receive is an array of coordinates with timeframe and other info. So, you might be able to receive more than 1 location coordinates with more than 1 timeframe.
Criteria to receive the location update:-
– Move at least 500 meters from the last known location
– At most 1 location update in 5 minutes.
If the device does not satisfy the above criteria but it is able to acquire new location coordinates, it will store the coordinates on the GPS chip. But once the criteria has been satisfied, iOS will send the array of coordinates to you through the location manager delegate methods.
I don’t know what exactly that you want to do with the “approaching a target”. I believe you might be able to use iOS Region Monitoring technology here and the technology will also wake up the app from the background or terminated/suspended mode.
Hi
I tested you solution and it is working fine thanks!
We implemented in our app but it will not works when we suspended app it goes to “applicationWillTerminate” function but in your code it goes to “applicationDidEnterBackground” Please help me.
I believe you have added the key “UIApplicationExitsOnSuspend” on your PList. With the key is implemented, your app will be suspended when you are moving the app to the background. If it is not an intention for the app that you developed, you should remove this key from the PList.
Thanks for your reply and we don’t have any key as “UI Application Exits On Suspend” on my PList. And Now sometime it is working fine. One question here, I have travelled more than 40 kilometers with this app. But i have only got 5 location updates. what is range to getting the location updates when we using the
start Monitoring Significant Location Changes and Is there any particular significant location on iOS map? Thanks in advance
If you don’t have the key “UIApplicationExitsOnSuspend” on PList, then “applicationWillTerminate” will not be called.
The minimum range to get the location update is 500 meters AND you will get at most 1 update in every 5 minutes. If you are travelling more than 10 km in 5 minutes, you also will get 1 location update.
You are getting 5 locations updates after travelled for 40 km, here is the potential conclusion that I can draw out:
– Assume that only 1 location update every 5 minutes.
– 5 updates * 5 minutes = 25 minutes (Let’s round up to 30 minutes).
– So, you are travelling about 40 km in 30 minutes
Conclusion: You are driving at about 80km/hour.
If you want to get more location updates, then you can drive slower. 😉
Ok Thanks Ricky. This significant location should get only we can move from one place another or if we stay in one place we can get the location for every 5 minute duration?
iOS will only send the location update to your app when the device is moving over 500 meters from the last known location. Without any movement, the app will not get the location.
Ok. Thank you very much Ricky.
Before you said that “The minimum range to get the location update is 500 meters AND you will get at most 1 update in every 5 minutes”
But we have travelled more than 200 km in this week end. We have got most of the location about my travel that is fine. In that there was very long duration to getting the location update from one to another, i mean its took more than 50 minutes duration between two location updates. Can you identify the issue why this was happening?
It could be anything. Your iPhone, your internet coverage and etc. Sometimes the GPS chip will store the location coordinates locally, you will receive an array of coordinates (with different timestamps) But sometimes due to very bad network (No 3G, only edge/GPRS or no network at all), GPS chip will not be able to determine the coordinates, thus, you are not getting any location update.
hi anad,
have u noticed that you are getting location when your phone screen is locked or in sleep mode.thats may be the reason.Hi Ricky,have u tested it with locked screen??
Yes, i can remember i didn’t used my iPhone its simply in locked mode.
But my entire travel it is in the same mode and i could received location update as well only the issue is some time it takes more than 50 minutes to gave another location update from old one.
Hi Ricky.
Great post!
I have a question. I’m developing an app that needs to get the user location in background (even when the app is suspended or terminated) every 2 minutes and send it to my server. Is there a way to do this? This is an emergency app so the location tracking is the most important feature (no matter battery drain, the user is notified about it).
Thanks!
Hi Cristian,
Yes, it is possible to get done. You will have to combine 2 solutions that I posted on Github. 😉
Thanks!!
Hi Again Ricky.
I’ve been trying to combine the solution of this post with the one of the old post, but when the app is suspended or terminated I don’t get the location. Can you give me a clue of where to start looking? For me the “start Monitoring Significant Location Changes” is useless as I always need the location every 2 minutes. Thank you very much!!!
Cristian, did you ever figure this out? I am trying to combine both solutions too and the problem I’m running into is that when my app is woken up from suspended/terminated state by a significant location change, then Ricky’s first solution for background updates fails to prolong the app’s execution time indefinitely, and my app is killed by the OS after about 3 minutes…
Hi Danny, I have the same problem, but I don’t use significant location changes. I need to get the location every 2 minutes ALWAYS (foreground, background, suspended and killed by the OS). I’m still trying hard to find a solution.
Christian – the only way to get location updates when app is suspended/terminated is to get your app woken back up by either a significant location change or by region monitoring. So I’d suggest you look into implementing one or both of those because I really don’t think there is any other way you have a chance of accomplishing your goal otherwise…
Hi,
Would you like to share the code?
Thanks Ricky.
Hi Ricky,
I’m using part of your code in my app that should track user location. Here it is: https://itunes.apple.com/us/app/nakarte-moi-druz-na-andeks/id886626229
But my users and me found very strange problem in this code, that I can’ t resolve for months. It starts sending coordinates from the past after few days staying in suspend mode.
Example:
App have became in suspend mode, and first days it works perfect. I receive correct coordinates every 500 m.
I started traveling through 3 points A,B and C in few days. At first I get right coordinates between A and B but, then I’ve came to point C app sent me point B coordinates and it doesn’t meter if screen was locked or not. Each point is far enough from others. So, did you test your code for a long time staying in suspend mode?
Thanks for gr8 solution above.
I am having sharedGPSInstance. when user logs in significant location update has started. when user put app in background I stop significant location monitoring and start again.
Then after traveling some distance i got the significant location update. On this update I am using startUpdatingLocation to start GPS to get continues GPS updates.
I got the updates for 3mi. after that app is suspended. why the applicaiton is suspending?
I am usgin same sharedGPSManger for location tracking.
Please help me. Thanks
I have started
Hi Ricky,
Thanks a lot for your post, it’s great !
I m following you since beginning and I reach a point that I am only wait “Lock Screen” issue to be solved.
if you fix it then the full scenario will be brilliant, you know, all people lock their iPHONE !
Regards,
Walid
Hi Ricky,
Two questions:
1) Do you find that when using the significant change service, the arrow icon is always present in the status bar, and that in “Settings>Privacy>Location Services”, the app always has a purple arrow icon?
2) In Xcode, is it necessary to set “Capabilities>Background Modes>Location” updates to on?
-Allan
Thanks for your post!
I have a question:
Instead I save new location to Plist file…
At function: -(void) locationManager: (CLLocationManager *)manager did Update Locations: (NSArray *) locations
-> Can I call webservice and send new location to server of my application?
I wonder is whether the my application execute code while app was killed?
Yes, I have the same question, will the app be able to send to the server about the location change to send a push notification for example, after being killed/suspended?
And also can I use geofencing instead of location updates in the app??
I appreciate your reply, as I need this feature urgently
Hello Ricky,
I am doing same thing with my application as you have implemented in the code. While I am debugging, it works completely perfect even if the iPhone is locked and application is in background, But while I am testing the same thing in live environment, iOS suspend the application. See the crash log.
CoreTime: Want active time in 4.40min. Need active time in 25.23min. Remaining retry interval: 1.466667min.
CoreTime: Want active time in 4.60min. Need active time in 25.44min. Remaining retry interval: 1.466667min.
CoreTime: Want active time in 4.79min. Need active time in 25.63min. Remaining retry interval: 1.450000min.
has active assertions beyond permitted time:
{(
id: 1243- EFED3B28- EE5B-4B14-8F41- A5B38030B8B2 name: Called by BCT, from -[AppDelegate setUpTimer WithTime:] process: permitted Background Duration: 180.000000 reason: finishTask owner pid:1243 preventSuspend prevent IdleSleep preventSuspend OnSleep
)}
: Application ‘UIKit Application: com.BCT.com[0xe023]’ exited abnormally via signal.
What I have done is I am playing with timer, i.e 150 seconds, a timer method will be called and location will be updated and the WS for updating location on server will be called. It works fine while application is foreground, I have googled out so many things and tried much for the same.
Also I am setting up
[UIApplication shared Application] setMinimum Background FetchInterval: 150];
And checking on
-(void)application: (UIApplication *) application performFetch With Completion Handler: (void (^)(UIBackground FetchResult)) completionHandler
if timers are invalid then I am updating the timers,
I would appreciate if you can help me to solve this problem.
Thanks and regards,
Vatsal.
From what you’ve said it seems that the best that the location services offers is an update around every 10 mins / 500 meters whilst in suspended mode. Are you saying that there is no way to get more frequent data whilst the app is in suspended mode?
Thanks again for this article,
it’s helped out so so much.
You’re a legend 🙂
Hi Ricky
Thanks for the Post!
Do you know if this solution works on iPhone 4?
Thanks again!
Shawn
Hi,
We’re developing an app that track bicycle behaviour.
Can we use the the event to start normal (detailed) collection of GPS data?
Will this solution also work after the device is rebooted?
Thanks!
Hi Rick ,
I followed your tutorial and used the below lines in the plist to get the location in the background but App got rejected.
UIBackgroundModes
location
fetch
Reason for Rejection :
Issue 1: We found that your app uses a background mode but does not include functionality that requires that mode to run persistently. This behavior is not in compliance with the AppStoreReviewGuidelines.
We noticed your app declares support for location in the UIBackgroundModes key in your Info.plist but does not include features that require persistent location.
Hi Sind,
Actually Rick’s way only include significant location updates, which do require locate as a background mode (but stills needs the “always” approval).
Typo above : significant location updates, which do *NOT* require locate as a background mode.
Hey hi Ricky
i have Question
Can I call webservice and send new location to server of my application?
whether the my application execute code while app was killed/suspende/or in background
i used your code but not find any proper solution.
Can You plz Help me.
thanks in advance
nice work, rick!
a TIP for a better app:
simply Add “Application supports iTunes file sharing” key so You can get plist directly from iTunes.
I am investigating there same issues, can we speak via mail?
Hi Rick,
Loved the article. i’m trying to send local notification inside of the
if ([ launchOptions objectForKey: UIApplication LaunchOptions LocationKey])
{
// here im calling for local notification
}
i think i’m getting in to this “if” but the local notification is not called.
is there some things that cant be used in this method?
thanks man
Hi Ricky,
I have implemented your solution in my app.
My app is being woken up but I did not get the location.
The location array doesn’t contains data.
Help.
Thanks,
Nilesh
Hi,
Thanks for the both tutorials! this is really helping a lot of issues I had in my app.
Is there anyone which combining the two tutorials and is willing to share the code. I tried to do this but to be honest I do not now how to start.
Thanks
Hii Ricky,
Thank you for sharing this valuable tutorial its really appreciating.
when applying your source code i getting null launchoptionkey i am using xcode 7 & 4s device with ios 9. can you tell me why would i get this.
Thanks!
Same here I also get null result when using launchOptionKey
Hi Ricky,
Thanks for your tutorial. But I have some question:
1. I really need to update location every N minutes. Could you share something about how to integrate with the previous post about get location every N minutes?
2. Could we integrate your example with PhoneGap/Cordova project?
3. Could we call some RestAPI to update location to server?
Thanks,
Jason
In iOS 9.3 Its not working and hot getting the location in when after the application suspend or killed by the use
Is this does’t require to set this value to “Yes” allowsBackgroundLocationUpdates
Hi, Can we call the service from background mode or when tha application is killed. Please reply if you have any solution.
have you find out any solution?
Did you find any solution? I am not able to get location updates after app is killed. Let me know if you found any solution. Thanks
Hi, How can we update the last known location to a server, Please respond back.. Thanks
hi
thanks for amazing tutorial
i cloned your project and installed on real device
but location update does not work good
just when app state has changed one location has been received that this new location in most times does not change(maybe iOS cached this)
but important point is that new this app works good on simulator location simulating!!!
i have not any idea why!!!!???
please help me
sorry for my english.
best.
Hi Ricky,
Thank you very much for sharing the great tutorial and example! For iOS it works perfectly!
Does someone has an idea if something similar is also possible with Android? (Start a background task of a terminated application) Is there a similar tutorial?
Hi Ricky,
Could also provide some help on implementing the same in swift.
hi to all,
Actually some time i am not able to fetch location(lattitude and longitude)
why this is happening i need to call startupdate again to get the current location
hi Rick,
thanks for amazing tutorial
i have use your code in my project but i have one query , i want to start location update in background when silent notification appears and start update location to server how should do it in your code. i am trying but it stop after one or two call. you have any solution.
Hi Ricky, Great article. Helped me a lot. But one thing.
I am able to get the location updates when user puts the app in background. I can get location updates like this forever. But when user kills the app, I don’t receive the location updates. I would like to show you my code. Please let me know how can we connect.
Hello Ricky, I have one project which needs to be update the location continuously after the app was terminated. I can send you an offer and we can discuss for the price. Please message me when you are available. Thanks.
Hi Ricky,
It is working on foreground and background state of the App. But it is not working/fetching location on suspended or terminated state.
Hiii RICKY
If Possible give me the source code for iOS swift as soon as possible.
Thank You in Advance