Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug an iPhone app that's supposed to be launched by location services, into the background, from a terminated state?

We're told, via Apple's docs on startMonitoringSignificantLocationChanges that the following behavior can be expected by an application using the signification change API:

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the locationManager:didUpdateLocations: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.

Source: Apple Docs

My question is, how would I go about debugging and/or testing this? As soon as I terminate the app I have no idea what's happening (i.e. debugging session gets killed with app). When will I know when or if iOS has launched my app in the background w/ the launchOption key of UIApplicationLaunchOptionsLocationKey set? More importantly than that, how do I know whether or not the block of code that gets executed is functioning properly? How can I test this scenario rapidly without having to drive around after terminating my app hoping the code I wrote magically works? Any help much appreciate!!

like image 470
John Erck Avatar asked Nov 07 '13 23:11

John Erck


People also ask

Is there a debug mode for iPhone?

Open the iPhone Settings menu. On an iPhone with an early version of iOS, access the Debug Console through Settings > Safari > Developer > Debug Console. When Safari on the iPhone detects CSS, HTML, and JavaScript errors, details of each display in the debugger.

How do I know if an app is running in the background on iOS?

To detect if an iOS application is in background or foreground we can simply use the UIApplication just like we can use it to detect many other things like battery state, status etc. The shared. application state is an enum of type State, which consists of the following as per apple documentation.


1 Answers

Use Xcode’s Debug > Attach to Process > By Process Identifier (PID) or Name… menu: you can provide the name of your process and Xcode will then wait until it launches to attach and start a debug session.

like image 173
Noah Witherspoon Avatar answered Oct 22 '22 00:10

Noah Witherspoon