OfflineSettingViewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 "iSalesNetwork.h"
  10. @interface OfflineSettingViewController ()
  11. @end
  12. @implementation OfflineSettingViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  17. bool offline = [defaults boolForKey:@"EnableOfflineMode"] ;
  18. self.switch_offline.on = offline;
  19. self.edgesForExtendedLayout = UIRectEdgeNone ;
  20. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  21. style:UIBarButtonItemStylePlain
  22. target:self
  23. action:@selector( onCloseClick:)];
  24. self.navigationItem.rightBarButtonItem = closeButton;
  25. self.tv_log.layer.borderWidth=1 ; //边框粗细
  26. self.tv_log.layer.borderColor=[UIColor darkGrayColor].CGColor; //边框颜色
  27. }
  28. - (void)onCloseClick:(UIButton *)sender {
  29. // if(self.onDismissVC)
  30. // self.onDismissVC();
  31. [self dismissViewControllerAnimated:true completion:nil];
  32. }
  33. - (void)didReceiveMemoryWarning {
  34. [super didReceiveMemoryWarning];
  35. // Dispose of any resources that can be recreated.
  36. }
  37. - (IBAction)onChangeOfflineSwitch:(id)sender {
  38. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  39. if(self.switch_offline.isOn==false)
  40. {
  41. //disable offline
  42. [defaults removeObjectForKey:@"EnableOfflineMode"];
  43. [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
  44. [defaults synchronize];
  45. }
  46. else
  47. {
  48. UIApplication * app = [UIApplication sharedApplication];
  49. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  50. NSString* ver = [defaults stringForKey:@"OfflineVer"] ;
  51. [appDelegate check_offline:ver];
  52. return;
  53. if(ver.length==0)
  54. {
  55. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Offline data does not exist, do you like download now?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  56. //block代码块取代了delegate
  57. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Download" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  58. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Checking offline data"];
  59. //init offline mode
  60. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  61. // [self check_offline];
  62. });
  63. }];
  64. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  65. [self.switch_offline setOn:false];
  66. //[RAUtils message_alert:@"No item in the cart" title:@"Offline" controller:self] ;
  67. }];
  68. [alertControl addAction:actionTwo];
  69. [alertControl addAction:alertthree];
  70. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  71. [self presentViewController:alertControl animated:YES completion:nil];
  72. }
  73. else
  74. {
  75. }
  76. }
  77. }
  78. -(void) download_file:(NSString*)url type:(NSString*)type
  79. {
  80. }
  81. -(void) onLogUpdate
  82. {
  83. UIApplication * app = [UIApplication sharedApplication];
  84. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  85. dispatch_async(dispatch_get_main_queue(), ^{
  86. self.tv_log.text = appDelegate.downloadlog;
  87. [self.tv_log scrollRangeToVisible:NSMakeRange(appDelegate.downloadlog.length-1,0)];
  88. });
  89. }
  90. /*
  91. #pragma mark - Navigation
  92. // In a storyboard-based application, you will often want to do a little preparation before navigation
  93. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  94. // Get the new view controller using [segue destinationViewController].
  95. // Pass the selected object to the new view controller.
  96. }
  97. */
  98. @end