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

将处理崩溃日志和恢复编辑的工作放到子线程中。

Pen Li пре 9 година
родитељ
комит
7fd8901c1a

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


+ 129 - 103
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -527,11 +527,10 @@ void UncaughtExceptionHandler(NSException *exception) {
     
 }
 
-- (void)handleUrgencyFile {
-    
+- (void)dealWithUrgencyFile {
     [self readUrgencyCache];
     
-    NSLog(@"urgencyDic: %@",self.urgencyDic);
+//    NSLog(@"urgencyDic: %@",self.urgencyDic);
     if (self.urgencyDic.allKeys.count > 2) {
         
         MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
@@ -549,7 +548,7 @@ void UncaughtExceptionHandler(NSException *exception) {
         
         id count = [self.urgencyDic objectForKey:@"count"];
         int level_count = count ? [count integerValue] : 0;
-
+        
         if (!level_count) {
             return;
         }
@@ -566,109 +565,132 @@ void UncaughtExceptionHandler(NSException *exception) {
             
             NSMutableDictionary *restored_data = [urgencyDic objectForKey:restored_data_key];
             
-            if ([className isEqualToString:@"CustomerEditViewController"]) {
-                // CustomerEditViewController
-                
-                NSString *contact_id = [urgencyDic objectForKey:@"contact_id"];
-                
-                NSMutableDictionary *params = [NSMutableDictionary dictionary];
-                
-                [params setValue:contact_id forKey:@"contact_id"];
-                CustomerEditViewController * cuseditVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
-                
-                cuseditVC.bnewcustomer=false;
-                cuseditVC.url_type = URL_RESTORE;
-                cuseditVC.request_url=URL_EDIT_CUSTOMER;
-                
-                cuseditVC.params = params;
-                cuseditVC.content_data_download = restored_data;
-                
-                //            cuseditVC.delegate=self;
-                
-                
-                [[mainVC navigationController] setNavigationBarHidden:NO animated:NO];
-                [mainVC.navigationController pushViewController:cuseditVC animated:false];
-                
-                
-                
-            } else if ([className isEqualToString:@"CreateOrderViewController"]) {
-                // CreateOrderViewController
-                
-                NSString *order_code = [urgencyDic objectForKey:@"order_code"];
-                int order_status = [[urgencyDic objectForKey:@"order_status"] intValue];
-                NSString *order_customer_id = [urgencyDic objectForKey:@"order_customer_id"];
-                
-                self.order_customer_id = order_customer_id;
-                
-                // 首先通过order code 打开订单
-                NSDictionary* order_json = [iSalesNetwork open_Order:order_code];
-                
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-                    if([[order_json valueForKey:@"result"] intValue]==2)
-                    {
-                        
-                        self.order_code = order_code;
-                        self.order_status = order_status;
-                        [self SetSo:order_code];
-                        
-                        
-                        self.customerInfo = [iSalesNetwork request_CustomerInfo:order_customer_id].mutableCopy;
-                        
-                        self.contact_id=[self.customerInfo valueForKey:@"customer_cid"];
-                        
-                        [mainVC reloadOrder:true immediately:false];
-                        [mainVC reloadCart:true immediately:false];
-                        
-                        
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:mainVC] ;
-                    }
-                });
-                
-                
-                
-                // 再place order
-                
-                NSMutableDictionary *params = [NSMutableDictionary dictionary];
-                
-                CreateOrderViewController * orderinfoVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
-                
-                orderinfoVC.disable_dropdown_refresh=true;
-                orderinfoVC.url_type = URL_RESTORE;
-                orderinfoVC.request_url=URL_CARTDELIVERY;
-                orderinfoVC.params = params;
-                orderinfoVC.content_data_download = restored_data;
-                orderinfoVC.resumeOrder = YES;
-                
-                [mainVC.navigationController pushViewController:orderinfoVC animated:true];
-                
-                
-            } else  if ([className isEqualToString:@"AddressEditorViewController"]) {
-                // AddressEditorViewController
-                
-                AddressEditorViewController * addressVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
-                
-                addressVC.url_type = URL_RESTORE;
-                addressVC.request_url=URL_ADDRESS_EDOTOR;
-                
-                NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-                
-                params[@"is_subaction"]=@"true";
-                addressVC.params = params;
-                addressVC.content_data_download = restored_data;
-                
-                
-                [mainVC.navigationController pushViewController:addressVC animated:true];
+            dispatch_async(dispatch_get_main_queue(), ^{
+               
+                if ([className isEqualToString:@"CustomerEditViewController"]) {
+                    // CustomerEditViewController
+                    
+                    NSString *contact_id = [urgencyDic objectForKey:@"contact_id"];
+                    
+                    NSMutableDictionary *params = [NSMutableDictionary dictionary];
+                    
+                    [params setValue:contact_id forKey:@"contact_id"];
+                    CustomerEditViewController * cuseditVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
+                    
+                    cuseditVC.bnewcustomer=false;
+                    cuseditVC.url_type = URL_RESTORE;
+                    cuseditVC.request_url=URL_EDIT_CUSTOMER;
+                    
+                    cuseditVC.params = params;
+                    cuseditVC.content_data_download = restored_data;
+                    
+                    //            cuseditVC.delegate=self;
+                    
+                    
+                    [[mainVC navigationController] setNavigationBarHidden:NO animated:NO];
+                    [mainVC.navigationController pushViewController:cuseditVC animated:false];
+                    
+                    
+                    
+                } else if ([className isEqualToString:@"CreateOrderViewController"]) {
+                    // CreateOrderViewController
+                    
+                    NSString *order_code = [urgencyDic objectForKey:@"order_code"];
+                    int order_status = [[urgencyDic objectForKey:@"order_status"] intValue];
+                    NSString *order_customer_id = [urgencyDic objectForKey:@"order_customer_id"];
+                    
+                    self.order_customer_id = order_customer_id;
+                    
+                    // 首先通过order code 打开订单
+                    NSDictionary* order_json = [iSalesNetwork open_Order:order_code];
+                    
+                    dispatch_async(dispatch_get_main_queue(), ^{
+                        //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                        if([[order_json valueForKey:@"result"] intValue]==2)
+                        {
+                            
+                            self.order_code = order_code;
+                            self.order_status = order_status;
+                            [self SetSo:order_code];
+                            
+                            
+                            self.customerInfo = [iSalesNetwork request_CustomerInfo:order_customer_id].mutableCopy;
+                            
+                            self.contact_id=[self.customerInfo valueForKey:@"customer_cid"];
+                            
+                            [mainVC reloadOrder:true immediately:false];
+                            [mainVC reloadCart:true immediately:false];
+                            
+                            
+                        }
+                        else
+                        {
+                            [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:mainVC] ;
+                        }
+                    });
+                    
+                    
+                    
+                    // 再place order
+                    
+                    NSMutableDictionary *params = [NSMutableDictionary dictionary];
+                    
+                    CreateOrderViewController * orderinfoVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
+                    
+                    orderinfoVC.disable_dropdown_refresh=true;
+                    orderinfoVC.url_type = URL_RESTORE;
+                    orderinfoVC.request_url=URL_CARTDELIVERY;
+                    orderinfoVC.params = params;
+                    orderinfoVC.content_data_download = restored_data;
+                    orderinfoVC.resumeOrder = YES;
+                    
+                    [mainVC.navigationController pushViewController:orderinfoVC animated:true];
+                    
+                    
+                } else  if ([className isEqualToString:@"AddressEditorViewController"]) {
+                    // AddressEditorViewController
+                    
+                    AddressEditorViewController * addressVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"AddressEditorViewController"];
+                    
+                    addressVC.url_type = URL_RESTORE;
+                    addressVC.request_url=URL_ADDRESS_EDOTOR;
+                    
+                    NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
+                    
+                    params[@"is_subaction"]=@"true";
+                    addressVC.params = params;
+                    addressVC.content_data_download = restored_data;
+                    
+                    
+                    [mainVC.navigationController pushViewController:addressVC animated:true];
+                    
+                }// class_name
                 
-            }// class_name
+            });
             
         }
-
+        
         
     }
+}
+
+- (void)handleUrgencyFile {
+    
+    __weak typeof(self) weakself = self;
+    
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+       
+        if (weakself) {
+            
+            __strong typeof(weakself) strongself = weakself;
+            
+            [strongself dealWithUrgencyFile];
+        }
+        
+        
+
+        
+    });
     
 }
 
@@ -847,7 +869,11 @@ void UncaughtExceptionHandler(NSException *exception) {
     //UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
     //  [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
     
-    [self handleErrorLog];
+    
+    
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        [self handleErrorLog];
+    });
     
     return YES;
 }