How to debug when implementing handleOpenURL message?

I am writing an iPhone application that can be launched using a custom URL. So, I redefine -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

To check my changes, I have to run the application in the simulator, and then exit and launch Safari. Then I enter my own URL in the address bar to start the application.

But every time the application starts, it crashes. I'm trying to figure out why, but when I set a breakpoint and run the application from the main screen (instead of Xcode), it doesn't seem to attach.

I even tried putting NSLog instructions in the handleOpenURL message, but they do not print to the console.

I suppose I can create UIAlertViews, but ... yes, yikes. Any other way to connect to a debugging session in a simulator?

+5
source share
5 answers

In Xcode 4, you can change the target scheme, and in the "Run" section of the "Information" tab, you can select the option "Wait for MyApp.app to start":

enter image description here

This will make the debugger wait until the next application launch and then join this process, rather than creating a new process for you. This will allow you to launch the application manually from Safari and use the debugger.

+14
source

Open the Console.app console (in the Utilities folder). Log messages should appear.

+7
source

Unit Test, AppDelegate?

+1

I have not tried this, but how to add breakpoint instruction code to the code:

#if TARGET_CPU_ARM == 1
#define breakpoint() __asm__ volatile ("bkpt 0")
#else   // !ARM - assume INTEL. Everything else will break
#define breakpoint() __asm__ volatile ("int3");
#endif
+1
source

add the following to the first line in hasleOpenURL:

[NSThread sleepForTimeInterval: 30.0] and place a breakpoint on the next line after.

After launching your application, you will have 30 seconds to go to Xcode and select from the menu: Run / "Join the process" and select the name of your application from the list. The debugger should stop at the breakpoint.

Remember to remove sleepForTimeInterval when done!

+1
source

All Articles