开发者

catch error when iphone is crashed (be aborted)

I tried to deploy my application in real device.

But when it running , my application is crashed (be aborted).

How can i catch message error to display the error what make app开发者_C百科lication be crashed?

Thank you.


First of all you can redirect Your logging to a file with this method:

+ (void)redirectNSLogToDocumentFolder {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);    
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];    
    NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];   
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}

just call it at the beginning of your app. After, all your NSLog() calls will be written to a file (with the date as name).

Then you can just connect your device to XCode and retrieve the file with the Organizer


Mmm I don't know.

But you could try using the debugger or Instruments which allows a lot of debugging methods :-)

What is saying the console logs ?

Good luck !


When you connect your device to your computer, the organizer window in Xcode will allow you to view crash logs from the device. These can be helpful in locating the source of the problem.

If you run your app on the device by debugging from Xcode, you should be able to use bt in gdb when the debugger breaks at the point of the error. This will print a backtrace that shows where the error happened. You can move up the back trace to the point in your code that had the error by typing up in gdb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜