iOSExceptioncaught CrashReport crashreport

第一种方法 使用ExceptionHandler
用网上的一段代码
#pragma mark -#pragma mark Application lifecycle- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point forcustomization after application launch. [windowmakeKeyAndVisible]; [NdUncaughtExceptionHandlersetDefaultHandler]; NSArray *array = [NSArray arrayWithObject:@"thereis only one objective in this arary,call index one, app will crashand throw an exception!"]; NSLog(@"%@", [array objectAtIndex:1]); returnYES;}基本接口展示:#import<Foundation/Foundation.h>@interface NdUncaughtExceptionHandler : NSObject {}+ (void)setDefaultHandler;+ (NSUncaughtExceptionHandler*)getHandler;@end//还可以选择设置自定义的handler,让用户取选择接口实现展示#import "NdUncaughtExceptionHandler.h"NSString *applicationDocumentsDirectory() { return[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject];}void UncaughtExceptionHandler(NSException *exception) { NSArray *arr = [exceptioncallStackSymbols]; NSString *reason = [exception reason]; NSString *name = [exception name]; NSString *url = [NSStringstringWithFormat:@"=============异常崩溃报告=============nname:n%@nreason:n%@ncallStackSymbols:n%@", name,reason,[arrcomponentsJoinedByString:@"n"]]; NSString *path = [applicationDocumentsDirectory()stringByAppendingPathComponent:@"Exception.txt"]; [urlwriteToFile:path atomically:YES encoding:NSUTF8StringEncodingerror:nil]; //除了可以选择写到应用下的某个文件,通过后续处理将信息发送到服务器等 //还可以选择调用发送邮件的的程序,发送信息到指定的邮件地址 //或者调用某个处理程序来处理这个信息}@implementation NdUncaughtExceptionHandler-(NSString *)applicationDocumentsDirectory { return[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) lastObject];}+ (void)setDefaultHandler{ NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);}+ (NSUncaughtExceptionHandler*)getHandler{ returnNSGetUncaughtExceptionHandler();}@end
第二种方法使用PLCrashReporter框架借鉴google的
PLCrashReporter provide an in-process CrashReporter frameworkfor the iPhone and Mac OS X. This framework is very helpful ingetting the crash report for your app from beta tester or realusers.
iOSExceptioncaught CrashReport crashreport

I’m not sure how most of the developer ask for the crashreport from their users, but one way is to ask them to connecttheir IOS device to iTune, get the crash report and send themmanually, but this is just too troublesome.
With PLCrashReporter, you can capture the logs and output acrash report and your users can choose to send the report to thedeveloper directly within the app.
To start using PLCrashReporter,
First download thesource release. Extract the package and run theXcode project, we need to build the crashreport framework using thesource before we can use it in our project.There are a lot of Targets, for this example lets use only thesimulator Target. Navigate to the CrashReporter-iPhoneSimulatorTarget. Under the Build Settings, set “Perform Single-ObjectPrelink” to “No”, “Mach-O Type” to “Static Library”.Select your simulator as iphone simulator and then clickbuild.A static library should be built now, navigate to your builddirectory for the PLCrashReporter, eg./Users/username/Library/Developer/Xcode/DerivedData/CrashReporter-(randomcharacters)/Build/Products/Debug-iphonesimulator and copy thelibCrashReporter-iphonesimulator.a to your project that use thePLCrashReporter.Now, download thePLCrashReporterbinary releaseand extract the framework to a local directory.
Open your new project, and add the CrashReporter framework toyour project. To add a new framework, click on your project name inXCode, click on your target, under ‘Build Phases’ ->‘Link Binary with libraries’, click the ‘+’, and ‘add other’. Lookfor the ‘libCrashReporter-iphonesimulator.a’ you’ve built and theCrashReporter.framework you’ve downloaded, add them into theproject.Now you are ready to use the CrashReporter framework. There’sa demo project in the source release you’ve downloaded, you can runthe project and see how it works.
For XCode 4, the CrashReporter might have problem in creatingthe report. If it doesn’t work, you can try to switch off the GDBdebugger. To do this, in XCode, go to Product ->Edit Scheme -> Select the debugger as ‘None’.
If it works, you should be able to see a report‘live_report.plcrash’ under your ‘applicationdirectory/library/caches/com.plausiblelabs.crashreporter.data/com.yourcompany.CrashReporterDemo/’after you trigger a crash in the demo project.
With PLCrashReporter, you can provide a simpler way for yourBeta tester or real users to send the crash report back toyou.





因為app常常crash 所以去google做了一下功課,找到了這篇:SendCrash Reports from withinApp,發現foursquare也是用 plcrashreporter這個framework,所以就來研究一下。


1.首先到 http://code.google.com/p/plcrashreporter/下載最新framework版本plcrashreporter1.0.1,然後import到自己的project裡面。

2.參考 Example iPhone Usage 的範例,本身是用xcode 4.1去compile& run,確定可以使用,但是如果發現

PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];

會造成crash的話,請確定一下是否是下載最新的plcrashreporter。


3.當app在執行期間發生了crash,下次再開啓app的時候,我們可以利用以下程式碼,將上次crash的crashreport寄給自己。

PLCrashReporter *crashReporter =[PLCrashReporter sharedReporter];
NSData *crashData;NSError *error;crashData = [crashReporterloadPendingCrashReportDataAndReturnError:&error];MFMailComposeViewController *picker =[[MFMailComposeViewController alloc] init];[picker addAttachmentData:crashDatamimeType:@"application/octet-stream"fileName:@"crashfile.crash"];[self presentModalViewController:pickeranimated:YES];[picker release];

4.拿到crashreport之後,打開plcrashreport 1.0.1裡面的toolfolder,利用裡面的plcrashutil解碼(termail裡面打入./plcrashutilconvert --format=iphoneexample_report.plcrash),可以得到完整的crashreport。
5.配合dsym file 做symbolicate即可以看到app crash在那個檔案的那一行。可參考http://blog.sina.com.cn/s/blog_67b7cb7b01014h2x.html6.如果發現沒辦法看到crash出現在那一行的話,我的解決辦法是將利用plcrashutil解碼後的crashreport裡面version 103改成 104,然後將所有的 ???(???) 取代成armv7,再做synbpilcate即可。



还有第三种采用 CrashKit 这个类库三种方法比较起来还是这个简单点,呵呵 ..去googlecode下载最新版本1.拷贝 CrashController , CrashLogger四个文件到项目中2.在AppDelegate中实现 CrashSaveDelegate 委托3.下面就可以在AppDelegate.m文件中实现代码CrashController *crash = [CrashControllersharedInstance];crash.delegate = self;// 类库提供两种方式 ,邮件和服务器//邮件[crashsendCrashReportsToEmail:@"crash@smartfulstudios.com" withViewController:appDelegate.navigationController];//服务器[crashsendCrashReportsToBugzScoutURL:@"https://smartfulstudios.fogbugz.com/api.asp" withUser:@".com" password:@"" forProject:@"Inbox" withArea:@"Misc"];完成这些,别忘记实现onCrash回调方法- (void)onCrash{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Crash" message:@"The App has crashed and will attemptto send a crash report" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];}
OK了.很简单!不过 crashkit 目前只支持 ipad3.0



  

爱华网本文地址 » http://www.aihuau.com/a/25101014/219137.html

更多阅读

学会独处 享受孤独 享受孤独 品味寂寞

学会独处 享受孤独 075100 河北省张家口市宣化区教师进修学校  霍 庆一位著名的西方哲学家认为:凡是有所成就的人都需要练习出一种忍受单调生活的能力。即忍受孤独的能力,品味孤独的能力。因为安静的生活是许多伟大人物的特征

《三角形的分类》评课水头五小 郑经凯 郑经翰

《三角形的分类》评课水头五小 郑经凯周素芬老师的这节《三角形的分类》课充分体现新课程倡导的“教学要求教师转变角色,转变观念,关注学生的发展,关注教学中知识与技能、过程与方法、情感态度和价值观三维目标的整合”的教学理念。

作文分析与应对  关于读书的话题作文 作文素材分析 话题

阅读下面的文字,根据要求写一篇不少于800字的文章。据有关部门调查,六年来我国国民图书阅读率持续走低:1999年为60.4%,2001年为54.2%,2003年为51.7%,而2005年为48.7%,首次低于50%。造成图书阅读率持续走低的原因是多方面的。识字的人为什

声明:《iOSExceptioncaught CrashReport crashreport》为网友蛋糕女孩的心事分享!如侵犯到您的合法权益请联系我们删除