Explorar o código

完成崩溃日志的保存与提交

Pen Li %!s(int64=9) %!d(string=hai) anos
pai
achega
4331c8af82

BIN=BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 0 - 1
RedAnt ERP Mobile/common/Functions/offline/OLDataProvider.m

@@ -6336,7 +6336,6 @@
 {
     NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
     
-    
     int limit = [[params valueForKey:@"limit"] intValue];
     int offset = [[params valueForKey:@"offset"] intValue];
     NSString* keyword = [params valueForKey:@"keyWord"];

+ 1 - 1
RedAnt ERP Mobile/common/data_provider/iSalesNetwork.h

@@ -115,7 +115,7 @@
 
 +(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo;
 
-
++(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code;
 //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset;
 //+(NSData*)fake_json:(NSString*) url;
 //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id category_id:(NSString*) category_id price_template:(int) price_template customid:(int) customid;

+ 93 - 1
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -15,6 +15,8 @@
 #import "OLDataProvider.h"
 #import "AFHTTPSessionManager.h"
 #import "SelectUploadOrderViewController.h"
+#import "iSalesDB.h"
+#import "iSalesNetwork.h"
 
 
 #define UNZIP_OPEN_FAILED 0
@@ -428,10 +430,97 @@
 ////      // Only allow portrait (standard behaviour)
 //    return UIInterfaceOrientationMaskAll;
 //}
+
+void UncaughtExceptionHandler(NSException *exception) {
+    
+    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+    NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
+    NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
+    NSString *versionNum = @"";
+#ifdef BUILD_NPD
+    versionNum = [NSString stringWithFormat:@"Version: npd %@ Build %@",version,build];
+#endif
+    
+#ifdef BUILD_HMLG
+    versionNum = [NSString stringWithFormat:@"Version: HOMELEGANCE %@ Build %@",version,build];
+#endif
+    
+    versionNum = [versionNum stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
+    /**
+     *  获取异常崩溃信息
+     */
+    NSArray *callStack = [exception callStackSymbols];
+    NSString *reason = [exception reason];
+    NSString *name = [exception name];
+    NSString *content = [NSString stringWithFormat:@"异常错误报告\n exception_name:  %@\n exception_reason:  \n%@ \n exception_callStackSymbols:  \n%@ \n",name,reason,[callStack componentsJoinedByString:@"\n"]];
+    
+    content = [content stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
+    
+
+    
+    NSString *sql = [NSString stringWithFormat:@"insert into errlog (errmsg,params) values ('%@','%@');",versionNum,content];
+    
+    [iSalesDB execSql:sql];
+}
+
+- (void)handleErrorLog {
+    
+    __block NSMutableArray *err_array = [NSMutableArray array];
+    [iSalesDB jk_query:@"select errmsg,params,create_time from errlog;" completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
+        
+        const char *version_char = (char *)sqlite3_column_text(stmt, 0);
+        const char *errlog_char = (char *)sqlite3_column_text(stmt, 1);
+        const char *dateTime_char = (char *)sqlite3_column_text(stmt, 2);
+        
+        if (version_char == NULL)
+            version_char = "";
+        if (errlog_char == NULL)
+            errlog_char = "";
+        if (dateTime_char == NULL)
+            dateTime_char = "";
+        
+        NSString *version_str = [NSString stringWithUTF8String:version_char];
+        NSString *errlog_str = [NSString stringWithUTF8String:errlog_char];
+        NSString *dateTime_str = [NSString stringWithUTF8String:dateTime_char];
+        
+        NSDictionary *err_dic = @{
+                                  @"version" : version_str,
+                                  @"errlog" : errlog_str,
+                                  @"time" : dateTime_str
+                                  };
+        
+        [err_array addObject:err_dic];
+        
+        
+    }];
+    
+    if (err_array.count) {
+        // 首先上传
+        for (NSDictionary *err_dic in err_array) {
+            
+            NSString *version = [err_dic objectForKey:@"version"];
+            NSString *errlog = [err_dic objectForKey:@"errlog"];
+            NSString *time = [err_dic objectForKey:@"time"];
+            
+            NSString *result = [NSString stringWithFormat:@"version: %@ \n crash_datetime: %@ \n",version,time];
+            
+            [iSalesNetwork err_log:errlog result:result module:@"crash" code:0];
+            
+        }
+        
+        //上传完成之后清表
+        [iSalesDB execSql:@"delete from errlog"];
+    }
+    
+    
+}
+
+
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
-    [DefaultAppearance init_appearance];
+    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
     
+    [DefaultAppearance init_appearance];
     
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
     NSString *cachefolder = [paths objectAtIndex:0];
@@ -557,6 +646,9 @@
     //    [self test_descrypt1];
     //UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
+    
+    [self handleErrorLog];
+    
     return YES;
 }
 //-(void)test_descrypt