1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //
- // ExceptionHandle.m
- // Exception_Class
- #import "ExceptionHandle.h"
- #import <UIKit/UIKit.h>
- static NSString *exceptionContent;
- @implementation ExceptionHandle
- +(void)catchException
- {
- //指定程序crash时,处理一些内容
- NSSetUncaughtExceptionHandler(& UncaughtExceptionHandler);
- }
- //程序将要crash之前,先执行此方法,此方法执行完毕之后,程序才会崩溃
- void UncaughtExceptionHandler(NSException *exception)
- {
- //异常名称
- NSString *name = exception.name;
- //异常原因
- NSString *reason = exception.reason;
- NSArray *array = exception.callStackSymbols;
-
- //当前时间
- NSString *timeString = [ExceptionHandle getCurrentTime];
- //获取当前设备
- NSString *model = [[UIDevice currentDevice] model];
- NSString *systemName = [[UIDevice currentDevice] systemName];
- NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
-
- //获取应用程序版本号
- NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
- //获取程序名字
- NSString *identifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
-
- // \n 换行
- exceptionContent = [NSString stringWithFormat:@"\n\n\n =======异常信息========\n时间:%@ \n设备名称:%@ \n设备型号:%@%@ \n当前应用程序版本号:%@ \n应用名称:%@驾校版 \n异常名称:%@ \n异常的原因:%@ \nCallStackSymbols:%@",timeString,model,systemName,systemVersion,version,identifier,name,reason,array];
-
- /**把异常崩溃信息发送至开发者邮件
- 这里要不要加上网络情况判断 然后在无网络时保存到本地 然后有网在上传?不做了
- */
-
- NSMutableString *mailUrl = [NSMutableString string];
- [mailUrl appendString:@"mailto:1033556420@qq.com"];
- [mailUrl appendFormat:@"?cc="];
- [mailUrl appendString:@"&subject=程序异常崩溃,请发送异常给程序猿,谢谢合作!"];
- [mailUrl appendFormat:@"&body=<b>%@</b> body!", exceptionContent];
- // 打开地址 PS:下面这个方法好像过期
- NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]];
-
- }
- +(NSString *)getCurrentTime
- {
- NSDate *date = [NSDate date];
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSString *dateString = [formatter stringFromDate:date];
- return dateString;
- }
- @end
|