-->

How do I debug an iPhone app that's supposed t

2019-02-05 22:20发布

问题:

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!!

回答1:

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.