//
//  AppDelegate.m
//  AntsContract
//
//  Created by Ray on 12/16/16.
//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
//

#import "AppDelegate.h"
#import "ACNetwork.h"

//#import "AFHTTPSessionManager.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.bEnable_Cache = true;
    
    
    [self leakingTest];
    return YES;
}
 -(void)leakingTest
{
 //   return;
    
    return;
    
    {
        
        
//        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            NSDictionary* json = nil;
            
                        NSString *zipfile = [[NSBundle mainBundle]pathForResource:@"GEIC - Home Improvement Contract 2017" ofType:@"pdf"];
            ////            NSData* data = [NSData dataWithContentsOfFile: filePath];
            
            json = [ACNetwork save_document:zipfile];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                
//                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                //                if([[logout_json valueForKey:@"result"] intValue]==2)
                //                {
                //                    self.welcomeLabel.text=@"Not sign in";
                //                    //                        [sender setTitle:@"Sign in" forState:UIControlStateNormal];
                //                    [bbitem setTitle:@"Sign in"];
                //
                //                    self.buttonHIC.enabled = false;
                //                    self.buttonSRL.enabled = false;
                //                    self.coverView.hidden = false;
                //                }
                //                else
                //                {
                //                    [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
                //                }
                
                if([[json valueForKey:@"result"] intValue]==2)
                {
                    
//                    [weakSelf.navigationController popToRootViewControllerAnimated:false];
                    //                                        if(weakSelf.OnSave)
                    //                                            weakSelf.OnSave(pdffile);
                    
                    
                }
                else
                {
                    //                                        [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save document" controller:self] ;
                }
                
                
            });
        });
        
        
        
    }
    
//    {
//        
//        
//        
//        
//        //        self.uploadProgress.progress = 0;
//        
//        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
//        
//        
//        {
//            
//            //    UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
//            //    [waitalert show];
////            
////            //            NSData *imageData = UIImagePNGRepresentation(self.imgview.image);
////            
////            AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
////            
////            
////            
////            NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
////            
////                        if(appDelegate.user!=nil)
////                            [params setValue:appDelegate.user forKey:@"user"];
////                        //    if(appDelegate.contact_id!=nil)
////                        //        [params setValue:appDelegate.contact_id forKey:@"contactId"];
////                        if(appDelegate.password!=nil)
////                            [params setValue:appDelegate.password forKey:@"password"];
////            
////            
////            [params setValue:[AESCrypt AES128Encrypt:appDelegate.user  key:@"usai2010"] forKey:@"user"];
////            [params setValue:[AESCrypt AES128Encrypt:appDelegate.password  key:@"usai2010"] forKey:@"password"];
////            
////            [params setValue:@"deviceMain" forKey:@"_operate"];
////
////            
////            UIDevice * dev = [UIDevice currentDevice];
////            NSUUID* uuid =dev.identifierForVendor;
////#if TARGET_IPHONE_SIMULATOR//模拟器
////            [params setValue:@"simulator_uuid" forKey:@"deviceid"];
////#elif TARGET_OS_IPHONE//真机
////            [params setValue:uuid.UUIDString forKey:@"deviceid"];
////#endif
//            
//            
////            
////            NSMutableString *body=[[NSMutableString alloc]init];
//            //参数的集合的所有key的集合
////            NSArray *keys= [params allKeys];
//////            DebugLog(@"================parms==================");
////            //遍历keys
////            for(int i=0;i<[keys count];i++)
////            {
////                //得到当前key
////                NSString *key=[keys objectAtIndex:i];
////                //如果key不是pic，说明value是字符类型，比如name：Boris
////                if(![key isEqualToString:@"pic"])
////                {
////                    //                    //添加分界线，换行
////                    //                    [body appendFormat:@"%@\r\n",MPboundary];
////                    //添加字段名称，换2行
////                    [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
////                    //添加字段的值
////                    [body appendFormat:@"%@\r\n",[params objectForKey:key]];
//////                    DebugLog(@"parameter: key=%@   value=%@",key,[params objectForKey:key]);
////                }
////            }
////            DebugLog(@"================parms==================");
//            
//            
//            
////            NSString *filePath = [[NSBundle mainBundle]pathForResource:@"GEIC - Home Improvement Contract 2017" ofType:@"pdf"];
////            NSData* data = [NSData dataWithContentsOfFile: filePath];
////            
////            NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:@"http://192.168.0.155/phpcms/admin.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
////                [formData appendPartWithFileData:data name:@"upfile" fileName:@"leak test" mimeType:@"application/zip"];
////            } error:nil];
//            
//            
//            //        NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//            //            [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
//            //        } error:nil];
//            //
//            AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
//            
//            
//            
//            //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
//            
//            //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
//            
//            //
//            NSProgress *progress = nil;
//            
//            NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
//                
//                //        [progress removeObserver:self forKeyPath:@"fractionCompleted"];
//                
//                
////                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
//                
//                if (error) {
//                    
////                    NSString* err_msg = [error localizedDescription];
////                    DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
////                    
////                    
////                    NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
////                    
////                    DebugLog(@"data string: %@",str);
////                    [RAUtils message_alert:@"Can not connect to server please try again." title:@"Save document" controller:weakSelf] ;
//                    
//                } else {
////                    DebugLog(@"response ");
//                    
//                    
//                    
////                    NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
////                    
////                    // 再将NSData转为字符串
////                    NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
////                    
////                    //            NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
////                    
////                    DebugLog(@"data string: %@",jsonStr);
////                    
////                    NSDictionary* json = responseObject;
////                    
////                    
////                    
////                    
////                    if([[json valueForKey:@"result"] intValue]==2)
////                    {
////                        
////                        [weakSelf.navigationController popToRootViewControllerAnimated:false];
////                        //
////                        //
////                        if(weakSelf.OnSave)
////                            weakSelf.OnSave(pdffile);
////                        
////                        
////                    }
////                    else
////                    {
////                        [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save document" controller:self] ;
////                    }
//                    
//                    
//                }
//                //  [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
//            }];
//            
//            
//            
//            
//            //  [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
//            //
//            
//            
//            
//            
//            
//            
//            [uploadTask resume];
//            
//        }
//    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-(void) Login:(NSString* )user pwd:(NSString*) pwd
{
    self.user = user;
    self.password = pwd;
    self.bLogin = true;
}
-(void) Logout
{
//    MainViewController * main_vc= (MainViewController*)self.main_vc;
//    [main_vc logoutOrder];
//    
//    
//    [main_vc hideMenu];
//    [main_vc switchToHome];
    self.user = nil;
    self.password=nil;
    self.bLogin = false;
    
    
//    self.user_icon=nil;
//    self.user_type = USER_ROLE_UNKNOWN;
//    self.bLogin = false;
//    self.contact_id=nil;
//    self.customerInfo = nil;
//    self.order_code = nil;
//    
//    [self.recent_model removeAllObjects];
//    
//    [self SetMode:nil];
    
}
@end
