views:

2103

answers:

2

I am currently developing an app that receives Push Notifications. I have this all working 100% through a PHP page. There are several different types of push notifications my app can receive. The PHP handles this and sends different packets of information to my app which are all received just fine.

However, when the users "views" the notification and my app launches, I obviously want to take a different action than I would if the user just launched the app manually - and on top of that, different actions depending on the push notification type. I have got this working fine... structurally.

One of my push types is supposed to open a UIView that makes several connections to several different servers and negotiates data back and forth. This UIView works fine when, for example, triggered from the main menu - however when my push notification is triggering this UIView to appear, the socket connections are not acting as expected.

Now my question is not about the sockets, but more so - How do you debug such a problem?? From what I can tell (I am relatively new) when the app launched from a push notification there is no way to link that execution to the debugger / console / etc... I am having a very difficult time trying to debug the code using UIAlertViews, as there are many lines of communication back and forth between the various servers.

Any advice you have for me would be greatly appreciated.

A: 

I'm not working with push notifications, so I don't know the exact working of push notifications. However, I'd try mimicking the receipt of a push notification by letting the main method of your program pretend a notification was posted if possible, or calling the application:didFinishLaunchingWithOptions: UIApplicationDelegate method from within the applicationDidFinishLaunching: method.

HTH - Cheers, Daan

drvdijk
Also a good idea, but mimicking is always 2nd best to debugging the real thing! Happy Coding!
Dutchie432
+36  A: 

You can now configure Xcode to attach the debugger to the app after you launch it, instead of launching the app through the debugger. This lets you debug things that vary based on the launch state of your application, such as URL schemes, pasteboards, and push notifications.

  1. In Xcode look in the Source bar, and below Targets there will be Executables.
  2. Bring up the inspector for your app in executables.
  3. Click on the Debugging tab tab in the inspector.
  4. Uncheck "Start executable after starting debugger"
  5. Check the "Wait for next launch/push notification"

Now when you click debug from Xcode instead of launching the app a window will display telling it is waiting for the app to launch. You then launch the app normally on the phone and Xcode attaches to it

Louis Gerbarg
I know this may not be appropriate, but I love you. :)
Dutchie432
Oh, one question though - my NSLog's dont seem to be printing...?
Dutchie432
When you launch this way your application's stdin, stdout, stderr are not routed into GDB's console, they are pointed where they are in a normal app launch. You can see NSLog()s in the device's system console by looking at the device in the organizer.
Louis Gerbarg
You taught me some very valuable points here. THANK YOU. I spent the past 2 days trying to debug something that I was able to fix within 20 minutes of your post.
Dutchie432
+ seems to not work in the simulator
stigi
of course not since the simulator can't receive Pushes..
Dutchie432
Had the same issue here, thank you so much for your help!
Farid