views:

591

answers:

3

I'm writing an iPhone app that can be started via a custom URL. So, I override - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

To test my changes, I have to run the app in the simulator, then quit out and launch Safari. I then type in my custom URL in the address bar to launch the app.

But every time I launch, the app crashes. I'm trying to figure out why, but when I set a breakpoint and launch the app from the home screen (instead of in XCode) it doesn't seem to attach.

I even tried putting NSLog statements in the handleOpenURL message, but they don't get printed to the console.

I suppose I could create UIAlertViews but... yeah, yikes. Any other way to connect to a debug session in the Simulator?

+4  A: 

Open up Console.app (in the Utilities folder). Your log messages should appear there.

Kailoa Kadano
To expand upon this, `NSLog` statements won't show up in the standard XCode console if the app wasn't launched from XCode (i.e. on the phone or within the simulator).
Frank Schmitt
This didn't work for me, but using the Console tab in the XCode Organizer window did...
David Maymudes
+1  A: 

Can you write a Unit Test that would exercise the functionality of your AppDelegate?

Jonathan Arbogast
I actually tried another way that is similar - I put a call to handleOpenURL in the applicationDidFinish launching message, and then launched as normal, and I was able to step through. And doing it that way didn't crash anything, it was only crashing via the steps described above.
bpapa
Is your handleOpenURL handler is relying on something that is setup in applicationDidFinishLaunching?
Jonathan Arbogast
Also, instead of trying to log to the console, can you save some information to a file?
Jonathan Arbogast
+1  A: 

I have not tried this but how about adding a breakpoint instruction inline in your 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
Roger Nolan