What's the best way to log debug info in an iphone app?

后端 未结 5 1637
执笔经年
执笔经年 2021-02-05 18:26

Is there some standard way or has anyone written something that allows you to log a message and have it be displayed either in a small scrolling section on the iphone screen or

相关标签:
5条回答
  • 2021-02-05 18:58

    For Swift, it's simply

    print("log msg")
    
    0 讨论(0)
  • 2021-02-05 19:00

    Use NSLog(@"Log message");

    0 讨论(0)
  • 2021-02-05 19:11

    The Objective-C (more correct, really) method is

    NSLog(@"message");
    

    But the standard C method will work also

    printf("message");
    
    0 讨论(0)
  • 2021-02-05 19:15

    I don't have enough 'reputation' to add a direct comment for your posting but: don't forget to go to XCode->Preferences->Debugging->On Start: Choose Show Console & Debugger

    You can of course choose just the Console or whatever, but you'll probably want the Debugger to. To use that, just click to the left of the line you want to break at. You can also toggle from 'Activate' to 'Deactivate' so you if you know that there are a bunch of breakpoints you don't need to hit in the beginning of your application set the debugging to Deactive (in the debugging window) and then, before you hit the UI element in your app you want to debug, toggle that same button to Activate so your breakpoints become active. Otherwise, you could of course just click Continue until you got to your section.

    Also, on the NSLog, if you start to accumulate a bunch of log statements, and you need to 'find' one in particular, it helps to do: NSLog(@"\n\n\nMy statement\n\n\n); which will give a bunch of line breaks. Also, for the uninitiated:

    NSLog(@"My int: %d my BOOL: %d", myInt, myBOOL);
    NSLog(@"My object of any NSObject: %@", anObjectOfAnyKind);
    NSLog(@"My float: %f",myFloat);
    

    Hope all of this is helpful and sorry if I got off track with the debugging bit ;)

    0 讨论(0)
  • 2021-02-05 19:21

    If your have an application that is crashing then your can ask the users you the crash log. The crash log contains information about what the application was doing when it crashed and the stack trace.

    iPhone app log files are also stored on your users computer, and are copied across everytime they sync their iPhone. ( Note that DEVICE_NAME will be the same name of your iPhone in iTunes, and each log file will begin with the name of the app. )

    Mac OS X : /Library/Logs/CrashReporter/MobileDevice//

    Windows XP: C:\Documents and Settings\Application Data\Apple computer\Logs\CrashReporter\

    Windows Vista: C:\Users\AppData\Roaming\Apple computer\Logs\CrashReporter\MobileDevice\

    0 讨论(0)
提交回复
热议问题