简体   繁体   English

在iphone应用程序中记录调试信息的最佳方法是什么?

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

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 in a separate window in the iphone simulator? 是否有一些标准方式或有任何人写了一些东西,允许你记录一条消息,并让它显示在iPhone屏幕上的小滚动部分或在iPhone模拟器的单独窗口中?

Update: For noobs like me and don't know, use the NSLog methods as decribed below and make sure you select Run->Console to display the console. 更新:对于像我这样的新手并且不知道,请使用下面描述的NSLog方法,并确保选择Run-> Console来显示控制台。

Would still like to know if anyone has written a simple logger that displays on the iphone itself.... 仍然想知道是否有人写过一个简单的记录器显示在iPhone本身....

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 我没有足够的“声誉”为您的帖子添加直接评论但是:不要忘记转到XCode-> Preferences-> Debugging-> On Start:选择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. 您也可以从“激活”切换到“取消激活”,这样您就知道在应用程序开始时不需要点击一堆断点,将调试设置为Deactive(在调试窗口中),然后,在您点击要调试的应用程序中的UI元素之前,将相同的按钮切换为“激活”,以便断点变为活动状态。 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上,如果你开始累积一堆日志语句,并且你需要特别“找到”一个,它有助于:NSLog(@“\\ n \\ n \\ nMy语句\\ n \\ n \\ n );这将给出一堆换行符。另外,对于不熟悉的人:

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 ;) 希望所有这些都有帮助,如果我偏离调试位,我很抱歉;)

The Objective-C (more correct, really) method is Objective-C(更正确,更真实)的方法是

NSLog(@"message");

But the standard C method will work also 但标准C方法也可以

printf("message");

使用NSLog(@“日志消息”);

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. iPhone应用程序日志文件也存储在用户计算机上,并且每次同步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. ) (请注意,DEVICE_NAME将与iTunes中的iPhone名称相同,并且每个日志文件都将以应用程序的名称开头。)

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

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

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

对于Swift来说,这很简单

print("log msg")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM