5

I am developing an application for iOS in Objective C with Xcode. This application schedules local push notifications every 6 hours and it is crashing when I open the push notifications.

I need to debug the error to solve it. I can have the mobile connected to Xcode, but as the app is executed from local push notification I can't see the error messages on my Xcode debug console, as I haven't launched my app from Xcode.

Is there a way to have the iOS device connected to my Mac and see what error is happening?

I know that I can go to the mobile settings to view logs, but these logs are too ambigous for me aren't giving any error.

bneely
  • 9,083
  • 4
  • 38
  • 46
gabicuesta
  • 329
  • 5
  • 17
  • Yes. Add NSLog statements to all the different methods called after opening the local notification and find out where exactly the crash happens. – dasdom May 22 '16 at 11:38
  • 1
    Possible duplicate of [How to debug app when launch by push notification in Xcode](https://stackoverflow.com/questions/24672341/how-to-debug-app-when-launch-by-push-notification-in-xcode) – Cœur May 08 '18 at 13:30

3 Answers3

9

In addition to opening the console log as described by @saurabhgoyal you can tell Xcode to wait for your app to launch and then attach the debugger to it when it does.

Select the scheme you're using to build your app, select edit scheme, and click on the run icon. Then Look for a pair of radio buttons titled "Launch" and select the one with the name "Wait for executable to be launched."

Then when you run your app in Xcode it builds it and installs it on the device but does not launch it.

When your notification fires and the app launches the debugger attaches to your app and you can debug as normal (except that NSLog statements don't print to the debug console any more - an annoyance.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • That's what I was expecting. Saved my day. – Sandeep Rana May 21 '19 at 11:28
  • Instructions on how to select and change scheme would be useful. Also, if the NSLog statements don't print to the debug console, what benefit does this approach give? My use case is trying to test clicking of push notifications and how they have handled. – JCutting8 Nov 28 '20 at 11:23
2

Yes there is a way to see device logs on Mac.

Connect your iOS device to the Mac system using USB

Launch Xcode–>Window–>Devices

Select your device from the left panel

Now you can see the logs on the screen including the background activities.

In order to save the running logs.

Reproduce the issue or start working on your device on a the app you wanted to capture the logs. After the issue is reproduced click on the Save Console icon bottom right corner Xcode screen

For more details please visit this link

Hope this Helps!

saurabh goyal
  • 328
  • 4
  • 11
1

Check your crash log

1.Launch Xcode on your desktop machine.

2.Open the Xcode Devices window. (Window menu -> Devices and Simulators, or Cmd-Shift-2.)

3.Find your device in the left sidebar, then select “device logs”.

Choose a Chrome crash (or multiple crashes) and select “Export” at the bottom of the Organizer window.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Balagurubaran
  • 549
  • 6
  • 18
  • I've changed "Organizer" (Xcode 5 and earlier) to "Devices" (Xcode 6 and later) in your answer, as Xcode 6 was released four years ago (2014) and Xcode 5 isn't supported at all anymore (you can't publish an iOS app with it anymore). – Cœur May 08 '18 at 13:23