Kaynağa Gözat

添加文件NotificationNameCenter,实现闪退情况下Contact编辑时的保存,以及重新启动应用登录时恢复编辑

Pen Li 9 yıl önce
ebeveyn
işleme
1947659c14

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


+ 5 - 2
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -124,11 +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:^{
         
         [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]];
         
         if ([self.class_name isEqualToString:@"CustomerEditViewController"]) {
             // CustomerEditViewController
@@ -169,7 +171,6 @@
         }
         
         
-        [appDelegate.urgencyDic setValue:self.changed_data forKey:[NSString stringWithFormat:@"%@_changed_data",self.class_name]];
         
         
     }];
@@ -203,7 +204,9 @@
     
     
     
-    self.changed_data = [[NSMutableDictionary alloc] init];
+    if (!self.changed_data) {
+        self.changed_data = [[NSMutableDictionary alloc] init];
+    }
     
     //    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
     //    //    closeButton.title = @"Close";

+ 1 - 0
RedAnt ERP Mobile/common/Functions/contact/CustomerEditViewController.m

@@ -96,6 +96,7 @@
 
 - (void)onSaveClick:(UIButton *)sender {
     // add params check here.
+    
     [self.lastedit endEditing:true];
     [self.lasttextview endEditing:true];
 //    self.cancommit=true;

+ 4 - 1
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -11,6 +11,7 @@
 #import "RetrievePassViewController.h"
 #import "UILabel+FontAppearance.h"
 #import "OLDataProvider.h"
+#import "NotificationNameCenter.h"
 
 
 @interface LoginViewController ()
@@ -227,7 +228,7 @@
             if(ret==RESULT_TRUE)
                 
             {
-                
+               
                 //
                 //                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
                 AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
@@ -278,6 +279,8 @@
                 //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
                 //                    [self.delegate LoginViewControllerDidLogin:self];
                 //                }
+                
+                [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
             }
             else
             {

+ 6 - 0
RedAnt ERP Mobile/iSales-NPD.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		4207D2841D8247CB001B4A67 /* NotificationNameCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4207D2831D8247CB001B4A67 /* NotificationNameCenter.m */; };
 		421C55021D81586D00CFA3B1 /* JKTimerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 421C55011D81586D00CFA3B1 /* JKTimerManager.m */; };
 		423A4ADC1D503A53005ECE4A /* createContact.json in Resources */ = {isa = PBXBuildFile; fileRef = 423A4ADB1D503A53005ECE4A /* createContact.json */; };
 		42969C021D52F31C00FF190A /* editContact.json in Resources */ = {isa = PBXBuildFile; fileRef = 42969C011D52F31C00FF190A /* editContact.json */; };
@@ -205,6 +206,8 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		4207D2821D8247CB001B4A67 /* NotificationNameCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotificationNameCenter.h; sourceTree = "<group>"; };
+		4207D2831D8247CB001B4A67 /* NotificationNameCenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NotificationNameCenter.m; sourceTree = "<group>"; };
 		421C55001D81586D00CFA3B1 /* JKTimerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JKTimerManager.h; sourceTree = "<group>"; };
 		421C55011D81586D00CFA3B1 /* JKTimerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JKTimerManager.m; sourceTree = "<group>"; };
 		423A4ADB1D503A53005ECE4A /* createContact.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = createContact.json; sourceTree = "<group>"; };
@@ -717,6 +720,8 @@
 				713F76BB1929F4A7006A7305 /* Main.storyboard */,
 				7162A5E41C58781000AB630E /* iSalesNavigationController.h */,
 				7162A5E51C58781000AB630E /* iSalesNavigationController.m */,
+				4207D2821D8247CB001B4A67 /* NotificationNameCenter.h */,
+				4207D2831D8247CB001B4A67 /* NotificationNameCenter.m */,
 				713F76C11929F4A7006A7305 /* Images.xcassets */,
 				713F76B01929F4A7006A7305 /* Supporting Files */,
 				713F76B11929F4A7006A7305 /* iSales-NPD-Info.plist */,
@@ -1465,6 +1470,7 @@
 				7162A5611C58724700AB630E /* CustomerInfoViewController.m in Sources */,
 				42B99E161D7D052A00E773CD /* SortItemCell.m in Sources */,
 				7162A5AB1C58735900AB630E /* PDFListViewController.m in Sources */,
+				4207D2841D8247CB001B4A67 /* NotificationNameCenter.m in Sources */,
 				71DF74681C575E7900F2789C /* EnumSelectViewController.m in Sources */,
 				71D99D301CEF02E700CA32DE /* CustomIOSAlertView.m in Sources */,
 				7162A5731C58728D00AB630E /* DetailTopicCell.m in Sources */,

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

@@ -17,6 +17,8 @@
 #import "SelectUploadOrderViewController.h"
 #import "iSalesDB.h"
 #import "iSalesNetwork.h"
+#import "NotificationNameCenter.h"
+#import "CustomerEditViewController.h"
 
 
 #define UNZIP_OPEN_FAILED 0
@@ -462,6 +464,11 @@ void UncaughtExceptionHandler(NSException *exception) {
     NSString *sql = [NSString stringWithFormat:@"insert into errlog (errmsg,params) values ('%@','%@');",versionNum,content];
     
     [iSalesDB execSql:sql];
+    
+    NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
+    NSString *urgencyFile = [cachePath stringByAppendingPathComponent:@"urgency"];
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    [NSKeyedArchiver archiveRootObject:appDelegate.urgencyDic toFile:urgencyFile];
 }
 
 - (void)handleErrorLog {
@@ -518,6 +525,78 @@ void UncaughtExceptionHandler(NSException *exception) {
     }
     
     
+}
+
+- (void)handleUrgencyFile {
+    
+//    id root = self.window.rootViewController;
+//    NSArray *child = self.window.rootViewController.childViewControllers;
+//    
+//    NSLog(@"rootViewController:%@",root);
+//    NSLog(@"child: %@",child);
+    
+    NSLog(@"urgencyDic: %@",self.urgencyDic);
+    if (self.urgencyDic.allKeys.count) {
+        
+        MainViewController *mainVC = [self.window.rootViewController.childViewControllers lastObject];
+        
+        NSString *user = [self.urgencyDic objectForKey:@"user"];
+        if (![user isEqualToString:self.user]) {
+            return;
+        }
+        
+        BOOL offline_mode = [[self.urgencyDic objectForKey:@"offline_mode"] boolValue];
+        if (!((self.offline_mode && offline_mode) || (!self.offline_mode && !offline_mode))) {
+            return;
+        }
+        
+        NSString *firstClassName = [self.urgencyDic objectForKey:@"firt_class_name"];
+        
+        NSString *changed_data_key = [NSString stringWithFormat:@"%@_changed_data",firstClassName];
+        NSMutableDictionary *changed_data = [self.urgencyDic objectForKey:changed_data_key];
+        
+        if ([firstClassName isEqualToString:@"CustomerEditViewController"]) {
+            // CustomerEditViewController
+           
+            NSString *contact_id = [self.urgencyDic objectForKey:@"contact_id"];
+            
+            NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
+            
+            
+            [params setValue:contact_id forKey:@"contact_id"];
+            CustomerEditViewController * cuseditVC =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
+            
+            cuseditVC.bnewcustomer=false;
+            cuseditVC.url_type = URL_REMOTE;
+            cuseditVC.request_url=URL_EDIT_CUSTOMER;
+            
+            cuseditVC.params = params;
+            cuseditVC.changed_data = changed_data;
+            
+//            cuseditVC.delegate=self;
+            
+            
+            [[mainVC navigationController] setNavigationBarHidden:NO animated:NO];
+            [mainVC.navigationController pushViewController:cuseditVC animated:false];
+            
+            
+            
+        } else if ([firstClassName isEqualToString:@"CreateOrderViewController"]) {
+            // CreateOrderViewController
+            
+            
+            
+            
+            
+        } else if ([firstClassName isEqualToString:@"AddressEditorViewController"]) {
+            // AddressEditorViewController
+            
+        }
+
+        
+    }
+    
+    
 }
 
 - (void)initialExceptionHandler {
@@ -529,16 +608,28 @@ void UncaughtExceptionHandler(NSException *exception) {
     NSString *urgencyFile = [cachePath stringByAppendingPathComponent:@"urgency"];
     
     if ([manager fileExistsAtPath:urgencyFile]) {
-        _urgencyDic = [NSMutableDictionary dictionaryWithContentsOfFile:urgencyFile];
+        
+        _urgencyDic = [NSKeyedUnarchiver unarchiveObjectWithFile:urgencyFile];
+        
+//        _urgencyDic = [NSMutableDictionary dictionaryWithContentsOfFile:urgencyFile];
     } else {
         _urgencyDic = [NSMutableDictionary dictionary];
     }
     
 }
 
+- (void)becomeObserver {
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUrgencyFile) name:LoginOK_HandleUrgencyFile_Notification object:nil];
+}
+
+- (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
     [self initialExceptionHandler];
+    [self becomeObserver];
     
     [DefaultAppearance init_appearance];
     

+ 16 - 0
RedAnt ERP Mobile/iSales-NPD/NotificationNameCenter.h

@@ -0,0 +1,16 @@
+//
+//  NotificationNameCenter.h
+//  iSales-NPD
+//
+//  Created by Jack on 16/9/9.
+//  Copyright © 2016年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface NotificationNameCenter : NSObject
+
+UIKIT_EXTERN  NSString  *LoginOK_HandleUrgencyFile_Notification;
+
+
+@end

+ 16 - 0
RedAnt ERP Mobile/iSales-NPD/NotificationNameCenter.m

@@ -0,0 +1,16 @@
+//
+//  NotificationNameCenter.m
+//  iSales-NPD
+//
+//  Created by Jack on 16/9/9.
+//  Copyright © 2016年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "NotificationNameCenter.h"
+
+@implementation NotificationNameCenter
+
+const NSString  *LoginOK_HandleUrgencyFile_Notification = @"LoginOK_HandleUrgencyFile_Notification";
+
+
+@end