|
|
@@ -13,9 +13,117 @@
|
|
|
#import "AESCrypt.h"
|
|
|
@implementation AppDelegate
|
|
|
|
|
|
+
|
|
|
+#pragma mark - Exception
|
|
|
+// 程序崩溃
|
|
|
+void UncaughtExceptionHandler(NSException *exception) {
|
|
|
+
|
|
|
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
+ [appDelegate handleUncaughtException:exception];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setupUncaughtExceptionHandler {
|
|
|
+ NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)handleUncaughtException:(NSException *)exception {
|
|
|
+
|
|
|
+ if (exception == nil) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 应用信息 */
|
|
|
+ NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
+ // 当前应用名称
|
|
|
+ NSString *app_Name = [infoDict objectForKey:@"CFBundleDisplayName"];
|
|
|
+ // 当前应用版本号码
|
|
|
+ NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
|
|
|
+ // 当前应用软件版本
|
|
|
+ NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
|
|
|
+ //设备名称
|
|
|
+ NSString* deviceName = [[UIDevice currentDevice] systemName];
|
|
|
+ //手机系统版本
|
|
|
+ NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
|
|
|
+ //手机型号
|
|
|
+ NSString* phoneModel = [[UIDevice currentDevice] model];
|
|
|
+
|
|
|
+ NSString *device_info = [NSString stringWithFormat:@"Version:%@ %@\nBuild:%@\nDevice:%@ %@ %@",app_Name,version,build,deviceName,phoneModel,phoneVersion];
|
|
|
+
|
|
|
+ /** 异常信息 */
|
|
|
+ NSArray *callStack = [exception callStackSymbols];
|
|
|
+ NSString *reason = [exception reason];
|
|
|
+ NSString *name = [exception name];
|
|
|
+
|
|
|
+ NSString *exception_info = [NSString stringWithFormat:@"%@\n%@\n%@",name,reason,[callStack componentsJoinedByString:@"\n"]];
|
|
|
+
|
|
|
+ DebugLog(@"Crash Info: \n%@",exception_info);
|
|
|
+
|
|
|
+ // save err msg
|
|
|
+ NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
+ NSString *err_log_path = [cachePath stringByAppendingPathComponent:@"err_log"];
|
|
|
+
|
|
|
+ NSMutableDictionary *err_dic;
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:err_log_path]) {
|
|
|
+ err_dic = [NSMutableDictionary dictionaryWithContentsOfFile:err_log_path];
|
|
|
+ } else {
|
|
|
+ err_dic = [NSMutableDictionary dictionary];
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *flag = [[NSUUID UUID] UUIDString];
|
|
|
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
|
+ [formatter setDateFormat:@"YYYY-MM-DD HH:mm:ss"];
|
|
|
+
|
|
|
+ NSDictionary *err_log = @{
|
|
|
+ @"device" : device_info,
|
|
|
+ @"exception" : exception_info,
|
|
|
+ @"time" : [formatter stringFromDate:[NSDate date]]
|
|
|
+ };
|
|
|
+
|
|
|
+ [err_dic setObject:err_log forKey:flag];
|
|
|
+ [err_dic writeToFile:err_log_path atomically:NO];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)handleErrMsg {
|
|
|
+ NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
+ NSString *err_log_path = [cachePath stringByAppendingPathComponent:@"err_log"];
|
|
|
+
|
|
|
+ NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
+
|
|
|
+ if ([manager fileExistsAtPath:err_log_path]) {
|
|
|
+
|
|
|
+ NSMutableDictionary *err_dic = [NSMutableDictionary dictionaryWithContentsOfFile:err_log_path];
|
|
|
+
|
|
|
+ NSArray *flags = [err_dic allKeys];
|
|
|
+ [flags enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
+
|
|
|
+ NSDictionary *err_log = [err_dic objectForKey:obj];
|
|
|
+
|
|
|
+ NSString *device_info = [err_log objectForKey:@"device"];
|
|
|
+ NSString *exception_info = [err_log objectForKey:@"exception"];
|
|
|
+ NSString *time = [err_log objectForKey:@"time"];
|
|
|
+
|
|
|
+ NSDictionary *resultDic = [RANetwork collectErrMsg:exception_info DeviceInfo:device_info Time:time];
|
|
|
+ int result = [[resultDic objectForKey:@"result"] intValue];
|
|
|
+ if (result == RESULT_TRUE) {
|
|
|
+ [err_dic removeObjectForKey:obj];
|
|
|
+ }
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [err_dic writeToFile:err_log_path atomically:NO];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - AppDelegate
|
|
|
+
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
|
{
|
|
|
// Override point for customization after application launch.
|
|
|
+
|
|
|
+ [self setupUncaughtExceptionHandler];
|
|
|
+ [self handleErrMsg];
|
|
|
+
|
|
|
[GMSServices provideAPIKey:@"AIzaSyBqS2pF7m1DlR5zwhAX_rBSD_9bTnpjYbQ"];
|
|
|
if (! [ApexMobileDB initializeDb])
|
|
|
// TODO: alert the user!
|