How to Debug Significant Location Change in iOS

If an app has registered to listen for significant location change notifications, but is subsequently terminated, iOS will automatically relaunch the app into the background, if a new notification arrives. iOS generates significant location change notifications as soon as the device moves 500 meters or more from its previous notification location. These notifications don’t arrive more frequently than once every five minutes. Therefore, it could be challenging to test or debug code that handles these notifications without driving around with your device.

This article outlines steps you can follow in order to debug (or test)
significant location change notifications using iOS
simulator and Xcode. We will use the SignificantlyChanged app as an example here, but you should be able to use the instructions listed here with any other app. SignificantlyChanged is a test app written specifically for this blog post. All it does is ask for user’s permission to use current location as soon as the app is launched. When the app goes to background, it registers for significant location change notifications. Finally, when the app is about to
enter foreground, it stops listening to those notifications.

Step 1: Open iPhone simulator (Xcode > Open Developer Tool > iOS Simulator).

Step 2: Reset simulator (iOS Simulator > Reset Contents and Settings…).

Step 3: Install SignificantlyChanged app on simulator. Allow the app to use your current location when asked.

Step 4: Click stop from Xcode (or use shortcut ⌘.) to terminate SignificantlyChanged.

Step 5: Make sure location simulation is turned off (select Debug > Location > None from iOS Simulator).

Step 6: Launch app by tapping the app icon from iOS simulator

Step 7: Send app to the background (⌘⇧H). This will cause the app to register for significant location change notifications.

Step 8: Terminate the app

Step 9: Edit SignificantlyChanged app’s scheme so that Xcode waits for the app to be launched manually.

edit_scheme.png

wait_for_app_to_be_launched_manually.png

Step 10: Set a breakpoint either inside the application:didFinishLaunchingWithOptions: method in app delegate or any other method that handles UIApplicationDidFinishLaunchingNotification.

Step 11: Click run from Xcode (or use shortcut ⌘R) to run SignificantlyChanged on simulator. You should see Waiting for SignificantlyChanged to Launch spinner.

waiting_for_app_to_launch.png

Step 12: Put location simulation mode to freeway (select Debug > Location > Freeway Drive from iOS simulator)

Step 13: Wait for a notification to arrive. It should arrive within 5 minutes. Once a notification arrives, your breakpoint (if you’ve set one) should be hit as shown in figure below.

app_did_finish_launching_break_point.png

 
216
Kudos
 
216
Kudos

Now read this

Fixing Core Data Concurrency Violations

With iOS 8.0 Apple gave us access to a tool for tracking down code that violates Core Data concurrency rules. This post outlines how to setup Xcode so that you can identify and fix the faulty code. Background # According to the Core Data... Continue →