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

实现闪退情况下NewAddr编辑时的保存,以及重新启动应用登录时恢复编辑

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

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


+ 4 - 4
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -124,13 +124,13 @@
     
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
     
-    NSLog(@"..... %@",self.class_name);
-    
-    [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:2 queue:nil repeats:YES action:^{
+    [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:30 queue:nil repeats:YES action:^{
         
         [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
         [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
-        [appDelegate.urgencyDic setValue:self.changed_data forKey:[NSString stringWithFormat:@"%@_changed_data",self.class_name]];
+        [appDelegate.urgencyDic setValue:self.content_data_download forKey:[NSString stringWithFormat:@"%@_changed_data",self.class_name]];
+        
+        
         
         if ([self.class_name isEqualToString:@"CustomerEditViewController"]) {
             // CustomerEditViewController

+ 1 - 1
RedAnt ERP Mobile/common/Functions/address/AddressEditorViewController.m

@@ -54,7 +54,7 @@
 }
 
 - (IBAction)onSaveClick:(id)sender {
-    
+
     // add params check here.
     [self.lastedit endEditing:true];
      [self.lasttextview endEditing:true];

+ 1 - 0
RedAnt ERP Mobile/common/const.h

@@ -33,6 +33,7 @@
 #define URL_REMOTE 1
 #define URL_LOCAL 0
 #define URL_NONE 2
+#define URL_RESTORE 3
 
 #define RETRY_DELAY 15 //offline getting data retry delay.
 #define DOWNLOAD_RETRY_TIMES 5 //retry times for single download.

+ 56 - 16
RedAnt ERP Mobile/iSales-NPD/AppDelegate.m

@@ -21,6 +21,7 @@
 #import "CustomerEditViewController.h"
 #import "CreateOrderViewController.h"
 #import "OrderDetailViewController.h"
+#import "AddressEditorViewController.h"
 
 #define UNZIP_OPEN_FAILED 0
 #define UNZIP_SUCCESS 1
@@ -466,11 +467,8 @@ void UncaughtExceptionHandler(NSException *exception) {
     
     [iSalesDB execSql:sql];
     
-    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
-    NSString *urgencyFile = [cachePath stringByAppendingPathComponent:@"urgency"];
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
-    NSLog(@"arkiver urgencyDic: %@",appDelegate.urgencyDic);
-    [NSKeyedArchiver archiveRootObject:appDelegate.urgencyDic toFile:urgencyFile];
+    [appDelegate writeUrgencyCache];
 }
 
 - (void)handleErrorLog {
@@ -563,11 +561,11 @@ void UncaughtExceptionHandler(NSException *exception) {
             CustomerEditViewController * cuseditVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
             
             cuseditVC.bnewcustomer=false;
-            cuseditVC.url_type = URL_REMOTE;
+            cuseditVC.url_type = URL_RESTORE;
             cuseditVC.request_url=URL_EDIT_CUSTOMER;
             
             cuseditVC.params = params;
-            cuseditVC.changed_data = changed_data;
+            cuseditVC.content_data_download = changed_data;
             
 //            cuseditVC.delegate=self;
             
@@ -623,43 +621,85 @@ void UncaughtExceptionHandler(NSException *exception) {
             CreateOrderViewController * orderinfoVC =[mainStoryBoard instantiateViewControllerWithIdentifier:@"CreateOrderViewController"];
             
             orderinfoVC.disable_dropdown_refresh=true;
-            orderinfoVC.url_type = URL_REMOTE;
+            orderinfoVC.url_type = URL_RESTORE;
             orderinfoVC.request_url=URL_CARTDELIVERY;
             orderinfoVC.params = params;
-            orderinfoVC.changed_data = changed_data;
+            orderinfoVC.content_data_download = changed_data;
             orderinfoVC.resumeOrder = YES;
             
             [mainVC.navigationController pushViewController:orderinfoVC animated:true];
             
             
-        } else if ([firstClassName isEqualToString:@"AddressEditorViewController"]) {
-            // AddressEditorViewController
+            NSString *second_class_name = [self.urgencyDic objectForKey:@"second_class_name"];
+            NSString *second_changed_data_key = [NSString stringWithFormat:@"%@_changed_data",second_class_name];
+            NSMutableDictionary *second_changed_data = [self.urgencyDic objectForKey:second_changed_data_key];
+            
+            if ([second_class_name 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";
+//                params[@"subaction_tag"]= [NSString stringWithFormat:@"%ld",(long)sender.tag];
+                addressVC.params = params;
+                addressVC.content_data_download = second_changed_data;
+                
+                
+//                addressVC.from = indexPath;
+                
+                [mainVC.navigationController pushViewController:addressVC animated:true];
+                
+            }
+
+            
+        } else {
             
         }
 
         
     }
     
-    
 }
 
-- (void)initialExceptionHandler {
-    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
+- (void)writeUrgencyCache {
+    if (!self.user) {
+        return;
+    }
     
+    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
+    NSString *urgencyFile = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_urgency",self.user]];
+
+    [NSKeyedArchiver archiveRootObject:self.urgencyDic toFile:urgencyFile];
+}
+
+- (void)readUrgencyCache {
     // 检查本地urgency文件,存在则加载进_urgencyDic
     NSFileManager *manager = [NSFileManager defaultManager];
     NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
-    NSString *urgencyFile = [cachePath stringByAppendingPathComponent:@"urgency"];
+    NSString *urgencyFile = [cachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_urgency",self.user]];
     
     if ([manager fileExistsAtPath:urgencyFile]) {
         
         _urgencyDic = [NSKeyedUnarchiver unarchiveObjectWithFile:urgencyFile];
+        [manager removeItemAtPath:urgencyFile error:nil];
         
-//        _urgencyDic = [NSMutableDictionary dictionaryWithContentsOfFile:urgencyFile];
     } else {
         _urgencyDic = [NSMutableDictionary dictionary];
     }
-    
+
+}
+
+- (void)initialExceptionHandler {
+    NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
+    [self readUrgencyCache];
 }
 
 - (void)becomeObserver {