OfflineSettingViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. //
  2. // OfflineSettingViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 5/11/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OfflineSettingViewController.h"
  9. #import "RANetwork.h"
  10. #import "MainViewController.h"
  11. #import "LoginViewController.h"
  12. #import "OLDataProvider.h"
  13. #import "OfflineUnlockViewController.h"
  14. //#import "SyncControlPanelViewController.h"
  15. @interface OfflineSettingViewController ()
  16. @end
  17. @implementation OfflineSettingViewController
  18. - (IBAction)onUnlockClicked:(id)sender {
  19. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Unlock offline" message:@"Unlock offline to sync with another account. Current user data will lost!" preferredStyle:UIAlertControllerStyleAlert];
  20. //block代码块取代了delegate
  21. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Unlock" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  22. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  23. sqlite3* db = [iSalesDB get_db];
  24. int offline_user_iscurrent=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
  25. [iSalesDB close_db:db];
  26. if(offline_user_iscurrent>0)
  27. {
  28. self.bunlock=true;
  29. }
  30. else
  31. {
  32. OfflineUnlockViewController * unlockvc =[[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineUnlockViewController"];
  33. unlockvc.returnValue = ^(bool blogin){
  34. self.bunlock=true;
  35. };
  36. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:unlockvc] ;
  37. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  38. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  39. [self presentViewController:navi animated:YES completion:^{
  40. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  41. DebugLog(@"LoginViewController present.........");
  42. // self.btop = false;
  43. // <#code#>
  44. }];
  45. }
  46. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  47. // //block代码块取代了delegate
  48. //
  49. //
  50. //
  51. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  52. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Remove Models From Cart"];
  53. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  54. //
  55. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  56. //
  57. // dispatch_async(dispatch_get_main_queue(), ^{
  58. //
  59. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  60. //
  61. // if([[cart_json valueForKey:@"result"] intValue]==2)
  62. // {
  63. //
  64. // [self end_edit];
  65. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  66. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  67. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  68. // }
  69. // else
  70. // {
  71. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  72. // }
  73. //
  74. //
  75. //
  76. // });
  77. // });
  78. //
  79. //
  80. // }];
  81. //
  82. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  83. // DebugLog(@"No");
  84. // }];
  85. // [alertControl addAction:actionOne];
  86. //
  87. // [alertControl addAction:alertthree];
  88. //
  89. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  90. //
  91. //
  92. // [self presentViewController:alertControl animated:YES completion:nil];
  93. //
  94. // DebugLog(@"%@",self.edit_select_arr);
  95. //
  96. //
  97. }];
  98. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  99. DebugLog(@"No");
  100. }];
  101. [alertControl addAction:actionOne];
  102. [alertControl addAction:alertthree];
  103. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  104. [self presentViewController:alertControl animated:YES completion:nil];
  105. }
  106. - (void)viewDidLoad {
  107. [super viewDidLoad];
  108. self.bunlock=false;
  109. // Do any additional setup after loading the view.
  110. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  111. bool offline = [defaults boolForKey:@"EnableOfflineMode"] ;
  112. NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
  113. NSString* lastsync = [defaults stringForKey:@"LastSync"] ;
  114. if(lastsync!=nil)
  115. self.label_sync.text = lastsync;
  116. if(ver==nil)
  117. self.label_ver.text=@"No offline data";
  118. else
  119. self.label_ver.text=ver;
  120. self.switch_offline.on = offline;
  121. self.edgesForExtendedLayout = UIRectEdgeNone ;
  122. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  123. style:UIBarButtonItemStylePlain
  124. target:self
  125. action:@selector( onCloseClick:)];
  126. self.navigationItem.rightBarButtonItem = closeButton;
  127. }
  128. - (IBAction)OnCheckUpdate:(id)sender {
  129. UIApplication * app = [UIApplication sharedApplication];
  130. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  131. if(appDelegate.bLogin==false)
  132. {
  133. LoginViewController * loginvc =[ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  134. loginvc.returnValue = ^(bool blogin){
  135. if(blogin)
  136. {
  137. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  138. {
  139. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  140. NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
  141. if(sender==nil)
  142. {
  143. [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
  144. // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
  145. // syncVC.action_string=@"Download";
  146. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
  147. //
  148. //
  149. //
  150. //
  151. //
  152. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  153. //
  154. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  155. // [self presentViewController:navi animated:YES completion:^{
  156. //
  157. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  158. //
  159. // DebugLog(@"about present.........");
  160. //
  161. // // self.btop = false;
  162. // // <#code#>
  163. // }];
  164. }
  165. else
  166. {
  167. 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];
  168. //block代码块取代了delegate
  169. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  170. [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
  171. // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
  172. // syncVC.action_string=@"Download";
  173. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
  174. //
  175. //
  176. //
  177. //
  178. //
  179. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  180. //
  181. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  182. // [self presentViewController:navi animated:YES completion:^{
  183. //
  184. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  185. //
  186. // DebugLog(@"about present.........");
  187. //
  188. // // self.btop = false;
  189. // // <#code#>
  190. // }];
  191. }];
  192. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  193. }];
  194. [alertControl addAction:actionTwo];
  195. [alertControl addAction:alertthree];
  196. [self presentViewController:alertControl animated:YES completion:nil];
  197. }
  198. }
  199. else
  200. {
  201. }
  202. }
  203. else
  204. {
  205. [RAUtils alert_view:@"Must login" title:@"Data sync"];
  206. }
  207. };
  208. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  209. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  210. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  211. [self presentViewController:navi animated:YES completion:^{
  212. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  213. DebugLog(@"LoginViewController present.........");
  214. // self.btop = false;
  215. // <#code#>
  216. }];
  217. }
  218. else
  219. {
  220. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  221. sqlite3* db = [iSalesDB get_db];
  222. int offline_user_iscurrent=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
  223. [iSalesDB close_db:db];
  224. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  225. NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
  226. if(offline_user_iscurrent==0 && ver!=nil)
  227. {
  228. if(!self.bunlock)
  229. {
  230. [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."];
  231. return;
  232. }
  233. else
  234. {
  235. ver=nil;
  236. NSString *clearTableSQL = @"delete from offline_contact;delete from offline_order;delete from offline_cart;";
  237. [iSalesDB execSql:clearTableSQL];
  238. }
  239. } else if (ver && self.bunlock) {
  240. ver = nil;
  241. }
  242. if(sender==nil)
  243. {
  244. [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
  245. // SyncControlPanelViewController * syncVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"SyncControlPanelViewController"];
  246. // syncVC.action_string=@"Download";
  247. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:syncVC] ;
  248. //
  249. //
  250. //
  251. //
  252. //
  253. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  254. //
  255. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  256. // [self presentViewController:navi animated:YES completion:^{
  257. //
  258. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  259. //
  260. // DebugLog(@"about present.........");
  261. //
  262. // // self.btop = false;
  263. // // <#code#>
  264. // }];
  265. }
  266. else
  267. {
  268. 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];
  269. //block代码块取代了delegate
  270. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  271. [appDelegate check_offline:ver useInternalAddress:self.switch_internal_address.isOn parentvc:self];
  272. }];
  273. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  274. }];
  275. [alertControl addAction:actionTwo];
  276. [alertControl addAction:alertthree];
  277. [self presentViewController:alertControl animated:YES completion:nil];
  278. }
  279. }
  280. }
  281. - (void)onCloseClick:(UIButton *)sender {
  282. // if(self.onDismissVC)
  283. // self.onDismissVC();
  284. [self dismissViewControllerAnimated:true completion:nil];
  285. }
  286. - (void)didReceiveMemoryWarning {
  287. [super didReceiveMemoryWarning];
  288. // Dispose of any resources that can be recreated.
  289. }
  290. - (IBAction)onChangeOfflineSwitch:(id)sender {
  291. UIApplication * app = [UIApplication sharedApplication];
  292. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  293. if(self.switch_offline.isOn==false)
  294. {
  295. //disable offline
  296. if(appDelegate.bLogin)
  297. {
  298. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
  299. [RANetwork request_logout:^(NSMutableDictionary *result) {
  300. NSMutableDictionary* return_json=result ;
  301. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  302. if([[return_json valueForKey:@"result"] intValue]==2)
  303. {
  304. [appDelegate Logout];
  305. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  306. [defaults removeObjectForKey:@"EnableOfflineMode"];
  307. [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  308. [defaults synchronize];
  309. #ifdef OFFLINE_MODE
  310. appDelegate.offline_mode =self.switch_offline.isOn;
  311. #endif
  312. #ifdef RA_NOTIFICATION
  313. [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  314. #else
  315. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  316. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  317. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  318. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  319. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  320. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  321. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  322. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  323. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  324. #endif
  325. [((MainViewController*)appDelegate.main_vc) switchToHome];
  326. }
  327. else
  328. {
  329. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  330. }
  331. }];
  332. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  333. //
  334. // NSDictionary* return_json = [RANetwork logout];
  335. //
  336. // dispatch_async(dispatch_get_main_queue(), ^{
  337. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  338. //
  339. //
  340. // if([[return_json valueForKey:@"result"] intValue]==2)
  341. // {
  342. //
  343. // [appDelegate Logout];
  344. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  345. // [defaults removeObjectForKey:@"EnableOfflineMode"];
  346. // [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  347. //
  348. // [defaults synchronize];
  349. //#ifdef OFFLINE_MODE
  350. // appDelegate.offline_mode =self.switch_offline.isOn;
  351. //#endif
  352. //
  353. //#ifdef RA_NOTIFICATION
  354. //
  355. // [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  356. //#else
  357. // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  358. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  359. //
  360. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  361. // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  362. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  363. //
  364. //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  365. //
  366. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  367. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  368. //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  369. //
  370. //
  371. //#endif
  372. //
  373. //
  374. //
  375. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  376. // }
  377. // else
  378. // {
  379. // // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  380. // }
  381. //
  382. //
  383. //
  384. //
  385. // });
  386. // });
  387. }
  388. else
  389. {
  390. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  391. [defaults removeObjectForKey:@"EnableOfflineMode"];
  392. [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  393. [defaults synchronize];
  394. #ifdef OFFLINE_MODE
  395. appDelegate.offline_mode =self.switch_offline.isOn;
  396. #endif
  397. #ifdef RA_NOTIFICATION
  398. [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  399. #else
  400. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  401. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  402. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  403. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  404. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  405. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  406. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  407. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  408. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  409. #endif
  410. [((MainViewController*)appDelegate.main_vc) switchToHome];
  411. }
  412. }
  413. else
  414. {
  415. bool haveofflineData=[OLDataProvider check_offlinedata];
  416. if(haveofflineData)
  417. {
  418. // have offline data
  419. if(appDelegate.bLogin)
  420. {
  421. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
  422. [RANetwork request_logout:^(NSMutableDictionary *result) {
  423. NSMutableDictionary* return_json = result;
  424. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  425. if([[return_json valueForKey:@"result"] intValue]==2)
  426. {
  427. [appDelegate Logout];
  428. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  429. [defaults removeObjectForKey:@"EnableOfflineMode"];
  430. [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  431. [defaults synchronize];
  432. #ifdef OFFLINE_MODE
  433. appDelegate.offline_mode =self.switch_offline.isOn;
  434. #endif
  435. #ifdef RA_NOTIFICATION
  436. [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  437. #else
  438. [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  439. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  440. [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  441. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  442. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  443. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  444. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  445. [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  446. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  447. #endif
  448. [((MainViewController*)appDelegate.main_vc) switchToHome];
  449. }
  450. else
  451. {
  452. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  453. }
  454. }];
  455. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  456. //
  457. // NSDictionary* return_json = [RANetwork logout];
  458. //
  459. // dispatch_async(dispatch_get_main_queue(), ^{
  460. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  461. //
  462. //
  463. // if([[return_json valueForKey:@"result"] intValue]==2)
  464. // {
  465. //
  466. // [appDelegate Logout];
  467. //
  468. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  469. // [defaults removeObjectForKey:@"EnableOfflineMode"];
  470. // [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  471. //
  472. // [defaults synchronize];
  473. //#ifdef OFFLINE_MODE
  474. // appDelegate.offline_mode =self.switch_offline.isOn;
  475. //#endif
  476. //
  477. //#ifdef RA_NOTIFICATION
  478. // [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  479. //#else
  480. // [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
  481. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  482. // [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
  483. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  484. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  485. //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  486. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  487. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  488. //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
  489. //#endif
  490. //
  491. //
  492. //
  493. //
  494. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  495. // }
  496. // else
  497. // {
  498. // // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
  499. // }
  500. //
  501. //
  502. //
  503. //
  504. // });
  505. // });
  506. }
  507. }
  508. else
  509. {
  510. //no offline data download form server first.
  511. // restore switch state.
  512. [self.switch_offline setOn:!self.switch_offline.isOn];
  513. 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];
  514. //block代码块取代了delegate
  515. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  516. [self OnCheckUpdate:nil];
  517. }];
  518. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  519. // [self.switch_offline setOn:false];
  520. //[RAUtils message_alert:@"No item in the cart" title:@"Offline" controller:self] ;
  521. }];
  522. [alertControl addAction:actionTwo];
  523. [alertControl addAction:alertthree];
  524. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  525. [self presentViewController:alertControl animated:YES completion:nil];
  526. }
  527. //
  528. // UIApplication * app = [UIApplication sharedApplication];
  529. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  530. //
  531. // NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
  532. // //
  533. // // [appDelegate check_offline:ver];
  534. // // return;
  535. //
  536. // // if(ver.length==0)
  537. // {
  538. //
  539. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Check offline update?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  540. // //block代码块取代了delegate
  541. //
  542. //
  543. // UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  544. // // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Checking offline data"];
  545. // //init offline mode
  546. // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  547. // //
  548. // //
  549. // // // [self check_offline];
  550. // // });
  551. // [appDelegate check_offline:ver];
  552. //
  553. //
  554. //
  555. // }];
  556. //
  557. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  558. // // [self.switch_offline setOn:false];
  559. // //[RAUtils message_alert:@"No item in the cart" title:@"Offline" controller:self] ;
  560. // }];
  561. //
  562. // [alertControl addAction:actionTwo];
  563. // [alertControl addAction:alertthree];
  564. //
  565. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  566. //
  567. //
  568. // [self presentViewController:alertControl animated:YES completion:nil];
  569. //
  570. //
  571. //
  572. //
  573. //
  574. //
  575. //
  576. //
  577. // }
  578. // else
  579. // {
  580. //
  581. // }
  582. }
  583. }
  584. -(void) download_file:(NSString*)url type:(NSString*)type
  585. {
  586. }
  587. /*
  588. #pragma mark - Navigation
  589. // In a storyboard-based application, you will often want to do a little preparation before navigation
  590. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  591. // Get the new view controller using [segue destinationViewController].
  592. // Pass the selected object to the new view controller.
  593. }
  594. */
  595. @end