| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //
- // OfflineSettingViewController.m
- // iSales-NPD
- //
- // Created by Ray on 5/11/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "OfflineSettingViewController.h"
- #import "iSalesNetwork.h"
- @interface OfflineSettingViewController ()
- @end
- @implementation OfflineSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- bool offline = [defaults boolForKey:@"EnableOfflineMode"] ;
-
- 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;
-
-
- self.tv_log.layer.borderWidth=1 ; //边框粗细
- self.tv_log.layer.borderColor=[UIColor darkGrayColor].CGColor; //边框颜色
-
-
- }
- - (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 {
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
- if(self.switch_offline.isOn==false)
- {
- //disable offline
- [defaults removeObjectForKey:@"EnableOfflineMode"];
- [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-
- [defaults synchronize];
- }
- else
- {
-
- 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:@"Offline data does not exist, do you like download now?" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Download" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Checking offline data"];
- //init offline mode
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
-
- // [self check_offline];
- });
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" 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
- {
-
- }
- -(void) onLogUpdate
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- self.tv_log.text = appDelegate.downloadlog;
-
- [self.tv_log scrollRangeToVisible:NSMakeRange(appDelegate.downloadlog.length-1,0)];
- });
-
-
- }
- /*
- #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
|