Is there a way to manually tell the device to dispatch a significant location change notification that will wake up any applications registered for this notification? This is for testing only, and I realize this private API call would get rejected upon submission to the app store.
-
2I dug through the private framework headers and could not find anything that resembled a trigger for this. It's not convenient to only be able to test this by getting in the car and driving around with a laptop. – Nick May 29 '11 at 02:46
-
2If you use the CLLocationManager didUpdateToLocation:fromLocation: delegate then you can use startUpdatingLocation instead of startMonitoringSignificantLocationChanges for test-purpose. With no filter set inside the CLLocationManager it calls didUpdateToLocation nearly every second if you have medium-good gps-reception. For test-purpose this could help. – thomas May 30 '11 at 12:14
-
1It's not really a matter of testing the output of CLLocationManager as much as the lifecycle of the app when "woken up" by a significant location change. – Nick Jun 03 '11 at 07:27
-
If you have an Apple Dev account, you may want to take a look at the iOS5 UIAutomation. It may eventually provide you with a solution. The only road-block is I don't know if you can put a program into background mode via UIAutomation. – Barney Mattox Jul 30 '11 at 08:03
-
FWIW [Xcode doesn't allow your apps to be suspended *properly*](https://forums.developer.apple.com/thread/14855) and you could get unexpected results. That is on a normal device, it would actually become suspended but since you're running through Xcode it would just stay in the background for debugging purposes... – mfaani Aug 11 '17 at 12:29
10 Answers
So two answers:
A) Hop on a train :-)
B) Use the simulator. In iOS 5.x simulator, there is a debug menu that has a location submenu. Choose freeway drive. This will start the simulator on an imaginary journey down the scenic 280 in Northern California. It gives you everything but the view: your app will get Significant Location Change updates, and will also be launched in the background if it has been suspended.
To verify that you are actually moving, launch safari in the simulator, and go to maps.google.com and click the little track my location button. You should be moving.
Awesome! Now how to debug the lifecycle problem of being launched by the system? Easy! Have xCode wait for your app to be launched to start debugging. From the Scheme menu, choose edit scheme. In the Run Scheme, and the Info tab, for the "Launch" setting choose : "Wait for My.app to launch".
Run your app once in the simulator, so that it starts monitoring for location updates, then force quit it, so that it is suspended. Add a break point in your application did finish launching function, and wait. As soon as your simulator has gone far enough, your application will be woken up, your breakpoint hit, and you are in the money.
But really, the train ride is more fun.

- 4,615
- 2
- 27
- 16
-
I was not aware that the simulator would actually trigger the SLC. I first asked this question in the days of iOS4.x and there truly was no solution (besides the train). Thanks for the response. – Nick Apr 10 '12 at 01:30
-
-
2
-
2
-
Not worked on ios7 http://stackoverflow.com/questions/18946881/background-location-services-not-working-in-ios-7 – Igor Nov 08 '13 at 12:19
-
-
is there any way to change the track ( scenic 280 in Northern California) to my own route – Sunny Shah Nov 18 '14 at 06:17
-
1
-
3iOS9.3 + xCode 7.3 update : This method works like a charm !! (NOTE : be sure to properly handle requestAlwaysAuthorization() + appropriate info.plst keys). Plus, setting distanceFilter = 500 made me receive location updates every 30-40 seconds (sometimes even ~15s) ;) – Vexy Apr 08 '16 at 12:52
-
AFAIK [Xcode doesn't allow your apps to be suspended properly](https://forums.developer.apple.com/thread/14855) and you could get unexpected results. That is on a normal device, it would actually become suspended but since you're running through Xcode it would just stay in the background for debugging purposes... – mfaani Aug 11 '17 at 12:29
-
15 year down the lane. Does this still work with XCode 9 ? I have done exactly everything as mentioned above. Waited roughly for 5 minutes. Nothing. – Dibzmania Dec 18 '17 at 23:39
-
@Dibzmania yes it does. This thing is so easy once we know what to do but was a massive pain trying to accomplish it on my own. – Khanal Jan 05 '18 at 23:39
-
Well, I've found that I can do this by toggling on and off Airplane mode and/or WiFi. Perhaps start the app with the device in airplane mode, then close the app and turn airplane mode off. That will turn the GPS on and force a location update to be dispatched.
-
1This didn't work for me to relaunch a terminated app that uses significant location change monitoring. – aslı Sep 11 '12 at 20:08
-
1Yes ! This was a very good idea ! My problem was to make the system launch my app when the device is locked and this "Airplane mode" solution worked like a charm on iOS 9 ! Thanks a lot ! – nverinaud Dec 21 '15 at 14:35
I also wanted to test the relaunch of my terminated app which uses significant change monitoring. I wrote a piece of code so that it would display a local notification when it gets launched by a location key in the launch options dictionary.
I ran my app in the simulator. Then killed it from the multitasking bar. Then I set the location of the iOS simulator to a custom location. I quit the simulator and started it again. My app received the significant location update and showed the local notification.

- 8,740
- 10
- 59
- 80
I was struggling with the same issue, how to test 'startMonitoringSignificantLocationChanges' and check if my app is receiving location updates when suspended.
I couldn't manage to catch the execution on a breakpoint but I managed to see the results of my implementation working by sending the new location data to the server.
The whole flow: - Implemented with 'startMonitoringSignificantLocationChanges' and an API call to my server to update the location latitude and longitude - Set the location updates background mode capability to true - Run the app so the location manager is initiated and the app is listening for location changes - Force closed the app - Set the debug->location on simulator to freeway drive - Opened maps to see if the location is changing - Waited on the server to see for location updates and was getting new results every about 3 minutes
However, I'm still not sure if this is fine enough on a real device.
I'm working on Xcode Version 6.0.1 (6A317); tested on Simulator iPhone 5s (8.0).

- 1,402
- 1
- 9
- 17
Adding to MagicSeth's answer, if you need to test this on a real device instead of a simulator, you can trigger a background launch with UIApplication.LaunchOptionsKey.location
key by disabling and re-enabling Location Services in General > Privacy screen in the Settings app.

- 146
- 1
- 3
-
-
I wasn't able to get the solution with the simulator to work, but this worked excellent on iOS 12. – duncanc4 Feb 13 '20 at 14:43
One thing I noticed in iOS 7 and Xcode 5.1.1 - If you are expecting SLC events to fire up your app into background mode, it may or may not hit the breakpoints you set. For me, sometimes the NSLog message are not even showing.
If that's the case for you, you can view NSLog outputs from the System Log. You can open the System Log from iOS Simulator's Debug menu.
Depending on your scenario I would suggest two solutions:
Use a Timer or LocalNotification that periodically calls stopMonitoringSignificantLocationChanges followed by startMonitoringSignificantLocationChanges which should trigger a new location to be sent to your code (might be the same Location as before).
Build your own GPS Simulator that you start in debug builds and that will call the same delegate methods like CLLocationManager would do.

- 1,650
- 2
- 14
- 23
-
-
There is an application lifecycle that is the essence of the question. The application is terminated, and is launched by the significant location change into the background. We need to test the behavior of the application once it is launched into the background, including lifespan and network communication. We worked out our issues by actually taking a day and driving around the city with a laptop monitoring the console for logging of activity. – Nick Jun 03 '11 at 07:23
In iOS 4, you can register for significant location changes. From the Apple docs: With this service, location updates are generated only when the user’s location changes significantly; thus, it is ideal for social applications or applications that provide the user with noncritical, location-relevant information. If the application is suspended when an update occurs, the system wakes it up in the background to handle the update. If the application starts this service and is then terminated, the system relaunches the application automatically when a new location becomes available. This service is available in iOS 4 and later, only on devices that contain a cellular radio.
See the Apple docs here and here.
Here is some example code to register for signification location updates:
- (void)startSignificantChangeUpdates {
// Create the location manager if it doesn't exist
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
}
The docs say: if you leave this service running and your application is subsequently suspended or terminated, the service automatically wakes up your application when new location data arrives. At wake-up time, your application is put into the background and given a small amount of time to process the location data. Because your application is in the background, it should do minimal work and avoid any tasks (such as querying the network) that might prevent it from returning before the allocated time expires. If it does not, your application may be terminated.

- 13,526
- 3
- 52
- 57
-
Thanks... I get how it works, and have been using it for some time. The question is how to **test** it without driving around in a car getting the device to trigger it. – Nick Oct 06 '11 at 18:28
-
Freeway drive
// MARK: - MKMapViewDelegate
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
guard let location = userLocation.location else { return }
print(location.speed)
}

- 45,645
- 31
- 257
- 263
Well, this is not possible as the application scope is limited to its own space and such kind of notification cannot be generated with Apple Documented APIs list. Of course.. if any undocumented API is used, application will get rejection from apple due to the use of undocumented/private API.

- 8,099
- 1
- 26
- 41
-
Obviously... Please read the question before answering. " This is for testing only, and I realize this private API call would get rejected upon submission to the app store." – Nick Jun 25 '11 at 18:14