| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824 |
- //
- // OfflineSettingViewController.m
- // iSales-NPD
- //
- // Created by Ray on 5/11/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "OfflineSettingViewController.h"
- #import "RANetwork.h"
- #import "MainViewController.h"
- #import "LoginViewController.h"
- #import "OLDataProvider.h"
- #import "OfflineUnlockViewController.h"
- //#import "SyncControlPanelViewController.h"
- @interface OfflineSettingViewController ()
- @end
- @implementation OfflineSettingViewController
- - (IBAction)onAboutClick:(id)sender {
- }
- - (IBAction)onUnlockClicked:(id)sender {
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Unlock offline" message:@"Unlock offline to sync with another account. Current user data will lost!" preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Unlock" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- sqlite3* db = [iSalesDB get_db];
- int offline_user_iscurrent=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
-
- [iSalesDB close_db:db];
-
-
- if(offline_user_iscurrent>0)
- {
- self.bunlock=true;
- }
- else
- {
- OfflineUnlockViewController * unlockvc =[[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineUnlockViewController"];
- unlockvc.returnValue = ^(bool blogin){
- self.bunlock=true;
- };
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:unlockvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
-
-
- }
-
-
-
-
- // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- // //block代码块取代了delegate
- //
- //
- //
- // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart"];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- // if([[cart_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [self end_edit];
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
- // }
- // else
- // {
- // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
- // }
- //
- //
- //
- // });
- // });
- //
- //
- // }];
- //
- // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- // DebugLog(@"No");
- // }];
- // [alertControl addAction:actionOne];
- //
- // [alertControl addAction:alertthree];
- //
- // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
- //
- //
- // [self presentViewController:alertControl animated:YES completion:nil];
- //
- // DebugLog(@"%@",self.edit_select_arr);
- //
- //
- }];
-
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
- [alertControl addAction:alertthree];
-
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.bunlock=false;
- // Do any additional setup after loading the view.
-
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- bool offline = [defaults boolForKey:@"EnableOfflineMode"] ;
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
- NSString* lastsync = [defaults stringForKey:@"LastSync"] ;
- if(lastsync!=nil)
- self.label_sync.text = lastsync;
-
- if(ver==nil)
- self.label_ver.text=@"No offline data";
- else
- self.label_ver.text=ver;
- self.switch_offline.on = offline;
-
-
-
- // self.edgesForExtendedLayout = UIRectEdgeNone ;
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onCloseClick:)];
- self.navigationItem.rightBarButtonItem = closeButton;
-
-
-
-
- }
- - (IBAction)OnCheckUpdate:(id)sender {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- loginvc.returnValue = ^(bool blogin){
-
-
- if(blogin)
- {
- if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
- {
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
-
- if(sender==nil)
- {
- [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
- // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
- // syncVC.action_string=@"Download";
- // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
- //
- //
- //
- //
- //
- // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
- //
- // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- // [self presentViewController:navi animated:YES completion:^{
- //
- // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
- //
- // DebugLog(@"about present.........");
- //
- // // self.btop = false;
- // // <#code#>
- // }];
- }
- else
- {
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Check offline update?" message:@"Please connect to WIFI network and plug charging cable, KEEP SCREEN ON AND KEEP APP RUNNING FOREGROUND, download data will take a while." preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
-
-
- // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
- // syncVC.action_string=@"Download";
- // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
- //
- //
- //
- //
- //
- // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
- //
- // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- // [self presentViewController:navi animated:YES completion:^{
- //
- // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
- //
- // DebugLog(@"about present.........");
- //
- // // self.btop = false;
- // // <#code#>
- // }];
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
-
- [alertControl addAction:actionTwo];
- [alertControl addAction:alertthree];
-
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
- }
-
-
- }
- else
- {
-
- }
- }
- else
- {
- [RAUtils message_alert:@"Must login" title:@"Data sync" controller:self];
- // [RAUtils alert_view:@"Must login" title:@"Data sync"];
- }
-
-
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
-
-
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- sqlite3* db = [iSalesDB get_db];
- int offline_user_iscurrent=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
-
- [iSalesDB close_db:db];
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
-
-
-
- if(offline_user_iscurrent==0 && ver!=nil)
- {
- if(!self.bunlock)
- {
-
- [RAUtils message_alert:@"Current login account is different from the offline account, to continue with sync, all current offline data will be erased, you must unlock offline lock first. " title:@"Sync denied." controller:self];
- // [RAUtils alert_view:@"Current login account is different from the offline account, to continue with sync, all current offline data will be erased, you must unlock offline lock first. " title:@"Sync denied."];
- return;
- }
- else
- {
- ver=nil;
- NSString *clearTableSQL = @"delete from offline_contact;delete from offline_order;delete from offline_cart;";
- [iSalesDB execSql:clearTableSQL];
-
- }
- } else if (ver && self.bunlock) {
- ver = nil;
- }
-
- if(sender==nil)
- {
- [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
- // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
- // syncVC.action_string=@"Download";
- // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
- //
- //
- //
- //
- //
- // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
- //
- // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- // [self presentViewController:navi animated:YES completion:^{
- //
- // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
- //
- // DebugLog(@"about present.........");
- //
- // // self.btop = false;
- // // <#code#>
- // }];
- }
- else
- {
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Check offline update?" message:@"Please connect to WIFI network and plug charging cable, KEEP SCREEN ON AND KEEP APP RUNNING FOREGROUND, download data will take a while." preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
-
- [alertControl addAction:actionTwo];
- [alertControl addAction:alertthree];
-
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
- }
-
-
-
- }
-
-
-
-
-
-
-
-
-
- }
- - (void)onCloseClick:(UIButton *)sender {
-
- // if(self.onDismissVC)
- // self.onDismissVC();
- [self dismissViewControllerAnimated:true completion:nil];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)onChangeOfflineSwitch:(id)sender {
-
-
-
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
-
-
-
- if(self.switch_offline.isOn==false)
- {
- //disable offline
-
-
- if(appDelegate.bLogin)
- {
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
- [RANetwork request_logout:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json=result ;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- [appDelegate Logout];
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- [defaults removeObjectForKey:@"EnableOfflineMode"];
- [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-
- [defaults synchronize];
- #ifdef OFFLINE_MODE
- appDelegate.offline_mode =self.switch_offline.isOn;
- #endif
-
- #ifdef RA_NOTIFICATION
-
- [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-
- [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-
-
- #endif
-
-
-
- [self dismissViewControllerAnimated:true completion:^{
- [((MainViewController*)appDelegate.main_vc) switchToHome];
- }];
- }
- else
- {
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
- }
- }];
-
-
-
-
-
-
-
-
- }];
- }];
-
-
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [RANetwork logout];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[return_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [appDelegate Logout];
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // [defaults removeObjectForKey:@"EnableOfflineMode"];
- // [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
- //
- // [defaults synchronize];
- //#ifdef OFFLINE_MODE
- // appDelegate.offline_mode =self.switch_offline.isOn;
- //#endif
- //
- //#ifdef RA_NOTIFICATION
- //
- // [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- //
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //
- //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- //
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- //
- //
- //#endif
- //
- //
- //
- // [((MainViewController*)appDelegate.main_vc) switchToHome];
- // }
- // else
- // {
- // // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
- // }
- //
- //
- //
- //
- // });
- // });
- }
- else
- {
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- [defaults removeObjectForKey:@"EnableOfflineMode"];
- [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-
- [defaults synchronize];
- #ifdef OFFLINE_MODE
- appDelegate.offline_mode =self.switch_offline.isOn;
- #endif
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- #endif
-
-
-
- [self dismissViewControllerAnimated:true completion:^{
- [((MainViewController*)appDelegate.main_vc) switchToHome];
- }];
- }
- }
- else
- {
- bool haveofflineData=[OLDataProvider check_offlinedata];
- if(haveofflineData)
- {
- // have offline data
- if(appDelegate.bLogin)
- {
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
- [RANetwork request_logout:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json = result;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- [appDelegate Logout];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- [defaults removeObjectForKey:@"EnableOfflineMode"];
- [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-
- [defaults synchronize];
- #ifdef OFFLINE_MODE
- appDelegate.offline_mode =self.switch_offline.isOn;
- #endif
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- #endif
-
-
- [self dismissViewControllerAnimated:true completion:^{
- [((MainViewController*)appDelegate.main_vc) switchToHome];
- }];
-
-
- }
- else
- {
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
- }
- }];
-
-
-
-
-
-
-
-
- }];
- }];
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [RANetwork logout];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // if([[return_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [appDelegate Logout];
- //
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- // [defaults removeObjectForKey:@"EnableOfflineMode"];
- // [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
- //
- // [defaults synchronize];
- //#ifdef OFFLINE_MODE
- // appDelegate.offline_mode =self.switch_offline.isOn;
- //#endif
- //
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
- //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- //#endif
- //
- //
- //
- //
- // [((MainViewController*)appDelegate.main_vc) switchToHome];
- // }
- // else
- // {
- // // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
- // }
- //
- //
- //
- //
- // });
- // });
- }
- }
- else
- {
- //no offline data download form server first.
- // restore switch state.
-
- [self.switch_offline setOn:!self.switch_offline.isOn];
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Offline data not found, download it from server?" message:@"Please connect to WIFI network and plug charging cable, KEEP SCREEN ON AND KEEP APP RUNNING FOREGROUND, download data will take a while." preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- [self OnCheckUpdate:nil];
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- // [self.switch_offline setOn:false];
- //[RAUtils message_alert:@"No item in the cart" title:@"Offline" controller:self] ;
- }];
-
- [alertControl addAction:actionTwo];
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
- }
-
- //
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //
- // NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
- // //
- // // [appDelegate check_offline:ver];
- // // return;
- //
- // // if(ver.length==0)
- // {
- //
- // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Check offline update?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- // //block代码块取代了delegate
- //
- //
- // UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- // // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Checking offline data"];
- // //init offline mode
- // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- // //
- // //
- // // // [self check_offline];
- // // });
- // [appDelegate check_offline:ver];
- //
- //
- //
- // }];
- //
- // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- // // [self.switch_offline setOn:false];
- // //[RAUtils message_alert:@"No item in the cart" title:@"Offline" controller:self] ;
- // }];
- //
- // [alertControl addAction:actionTwo];
- // [alertControl addAction:alertthree];
- //
- // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
- //
- //
- // [self presentViewController:alertControl animated:YES completion:nil];
- //
- //
- //
- //
- //
- //
- //
- //
- // }
- // else
- // {
- //
- // }
- }
- }
- -(void) download_file:(NSString*)url type:(NSString*)type
- {
-
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|