Преглед изворни кода

1.修改Apex Mobile,替换新图标。
2.修改Apex Mobile,增加异常处理。

Pen Li пре 8 година
родитељ
комит
c66f8628e1

+ 108 - 0
Apex Mobile/Apex Mobile/AppDelegate.m

@@ -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!

BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_about.imageset/mode_about.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_about.imageset/mode_about@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_about.imageset/mode_about@3x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_change_password.imageset/mode_change_password.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_change_password.imageset/mode_change_password@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_change_password.imageset/mode_change_password@3x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_logout.imageset/mode_logout.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_logout.imageset/mode_logout@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_logout.imageset/mode_logout@3x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_message.imageset/mode_message.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_message.imageset/mode_message@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/mode_message.imageset/mode_message@3x.png


+ 2 - 0
Apex Mobile/Apex Mobile/RANetwork.h

@@ -36,4 +36,6 @@
 +(int) RetrievePassword : (NSString*) user  email:(NSString*) email;
 +(int) ChangePassword : (NSString*) newpass user:(NSString*) user oldpass:(NSString*) oldpass;
 +(bool) UpdateServiceLocation;
++ (NSDictionary *)collectErrMsg:(NSString *)errMsg DeviceInfo:(NSString *)deviceInfo Time:(NSString *)time;
+
 @end

+ 22 - 0
Apex Mobile/Apex Mobile/RANetwork.m

@@ -1160,5 +1160,27 @@
     
 }
 
++ (NSDictionary *)collectErrMsg:(NSString *)errMsg DeviceInfo:(NSString *)deviceInfo Time:(NSString *)time {
+    
+    NSMutableDictionary *params = [@{
+                              @"device_info" : deviceInfo == nil ? @"" : deviceInfo,
+                              @"crash_info" : errMsg == nil ? @"" : errMsg,
+                              @"crash_time" : time == nil ? @"" : time
+                              } mutableCopy];
+    
+    NSData* json=[self get_json:URL_ERR_LOG parameters:params  file:nil];
+    
+    if (json==nil)
+    {
+        return @{
+                 @"result" : @RESULT_NET_ERROR,
+                 @"err_msg" : MSG_NET_ERROR
+                };
+    }
+    
+    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
+    
+    return resultDic;
+}
 
 @end