TimeSynViewController.mm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // TimeSynViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/12.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "TimeSynViewController.h"
  9. #import "ItemViewController.h"
  10. #import "ItemTableviewCell.h"
  11. #import "TimeSynConfig.h"
  12. #import "Header.h"
  13. @interface TimeSynViewController () <UITableViewDelegate,UITableViewDataSource,TimeSynConfigDelegate>
  14. {
  15. TimeSynConfig *config; //时间同步,包括夏令时、时区、时间等
  16. UITableView *tableV;
  17. NSMutableArray *titleArray;
  18. }
  19. @end
  20. @implementation TimeSynViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. //初始化tableview数据
  24. [self initDataSource];
  25. [self configSubView];
  26. //获取设备时间信息
  27. [self getTimeSynConfig];
  28. }
  29. - (void)viewWillDisappear:(BOOL)animated{
  30. //有加载状态、则取消加载
  31. if ([SVProgressHUD isVisible]){
  32. [SVProgressHUD dismiss];
  33. }
  34. }
  35. #pragma mark - 获取设备夏令时,时区、时间信息
  36. - (void)getTimeSynConfig {
  37. [SVProgressHUD showWithStatus:TS("")];
  38. if (config == nil) {
  39. config = [[TimeSynConfig alloc] init];
  40. config.delegate = self;
  41. }
  42. //调用获取设备时间信息的接口
  43. [config getTimeZoneConfig];
  44. }
  45. #pragma mark 获取摄像机时间代理回调
  46. - (void)getTimeSynConfigResult:(NSInteger)result {
  47. if (result >0) {
  48. //成功,刷新界面数据
  49. [self.tableV reloadData];
  50. [SVProgressHUD dismiss];
  51. }else{
  52. [MessageUI ShowErrorInt:(int)result];
  53. }
  54. }
  55. #pragma mark - 保存摄像机时间配置 (时区、夏令时、时间)
  56. -(void)saveConfig{
  57. [SVProgressHUD show];
  58. [config setTimeSynConfig];
  59. }
  60. #pragma mark 保存摄像机时间代理回调
  61. - (void)setTimeSynConfigResult:(NSInteger)result {
  62. if (result >0) {
  63. //成功
  64. [SVProgressHUD dismissWithSuccess:TS("Success")];
  65. }else{
  66. [MessageUI ShowErrorInt:(int)result];
  67. }
  68. }
  69. #pragma mark - tableView代理方法
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  71. return titleArray.count;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  75. if (!cell) {
  76. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  77. }
  78. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  79. NSString *title = [titleArray objectAtIndex:indexPath.row];
  80. cell.textLabel.text = title;
  81. if ([title isEqualToString:TS("summer")]) {
  82. cell.Labeltext.text = [config getDSTRule];
  83. }else if ([title isEqualToString:TS("time_zone")]) {
  84. cell.Labeltext.text =[config getTimeZone];
  85. }else if ([title isEqualToString:TS("time")]) {
  86. cell.Labeltext.text =[config getTimeQuery];
  87. }else if([title isEqualToString:TS("Time_synch")]){
  88. }
  89. return cell;
  90. }
  91. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  92. NSString *titleStr = titleArray[indexPath.row];
  93. if ([titleStr isEqualToString:TS("Time_synch")]) {
  94. [config setTimeSynConfig];
  95. }
  96. }
  97. #pragma mark - 界面和数据初始化
  98. - (void)configSubView {
  99. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  100. self.navigationItem.rightBarButtonItem = rightButton;
  101. [self.view addSubview:self.tableV];
  102. }
  103. - (UITableView *)tableV {
  104. if (!tableV) {
  105. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  106. tableV.delegate = self;
  107. tableV.dataSource = self;
  108. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  109. }
  110. return tableV;
  111. }
  112. #pragma mark - 界面和数据初始化
  113. - (void)initDataSource {
  114. titleArray = (NSMutableArray*)@[TS("summer"),TS("time_zone"),TS("time"),TS("Time_synch")];
  115. }
  116. - (void)didReceiveMemoryWarning {
  117. [super didReceiveMemoryWarning];
  118. // Dispose of any resources that can be recreated.
  119. }
  120. @end