car in 場站查車鎖車 ios
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

228 行
9.4KB

  1. //
  2. // ViewController.m
  3. // goodpk
  4. //
  5. // Created by 歐特儀 on 2020/2/11.
  6. // Copyright © 2020 Altob. All rights reserved.
  7. //
  8. #import "ViewController.h"
  9. #import "HelpInfoViewController.h"
  10. #import "InquireCarViewController.h"
  11. #import "CarSecurityViewController.h"
  12. #import "PaymentViewController.h"
  13. @interface ViewController ()
  14. @property (weak, nonatomic) IBOutlet UIButton *b1;
  15. @property (weak, nonatomic) IBOutlet UIButton *b2;
  16. @property (weak, nonatomic) IBOutlet UIButton *b3;
  17. @property (weak, nonatomic) IBOutlet UIButton *b4;
  18. @property (weak, nonatomic) IBOutlet UIButton *stationBtn;
  19. @property (weak, nonatomic) IBOutlet UILabel *stationName;
  20. @property (weak, nonatomic) IBOutlet UIImageView *EndBg;
  21. @property NSUserDefaults* defaults;
  22. @property NSMutableArray *StationData;
  23. @property NSString* station;
  24. @end
  25. @implementation ViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. [self setTitle:@"CAR IN! 智慧停車"];
  30. //注册截圖通知
  31. [[NSNotificationCenter defaultCenter] addObserver:self
  32. selector:@selector(userDidTakeScreenshot:)
  33. name:UIApplicationUserDidTakeScreenshotNotification object:nil];
  34. self.StationData = @[
  35. @{@"name":@"市民廣場", @"code":@"40808"},
  36. @{@"name":@"新體", @"code":@"12143"},
  37. @{@"name":@"二重公園", @"code":@"40806"},
  38. @{@"name":@"金城", @"code":@"12117"},
  39. @{@"name":@"澳底", @"code":@"12145"}
  40. ];
  41. [self setBtnListener];
  42. }
  43. - (void)viewDidAppear:(BOOL)animated{
  44. [super viewDidAppear:animated];
  45. self.defaults = [NSUserDefaults standardUserDefaults];
  46. if (! [self.defaults boolForKey:@"notFirstRun"]) {
  47. //App初次啟動
  48. [self showAlert];
  49. }
  50. }
  51. -(void) setBtnListener{
  52. [self.b1 setTag:0];
  53. [self.b2 setTag:1];
  54. [self.b3 setTag:2];
  55. [self.b4 setTag:3];
  56. [self.b1 addTarget:self
  57. action:@selector(handleButtonClicked:)
  58. forControlEvents:UIControlEventTouchUpInside
  59. ];
  60. [self.b2 addTarget:self
  61. action:@selector(handleButtonClicked:)
  62. forControlEvents:UIControlEventTouchUpInside
  63. ];
  64. [self.b3 addTarget:self
  65. action:@selector(handleButtonClicked:)
  66. forControlEvents:UIControlEventTouchUpInside
  67. ];
  68. [self.b4 addTarget:self
  69. action:@selector(handleButtonClicked:)
  70. forControlEvents:UIControlEventTouchUpInside
  71. ];
  72. [self.stationBtn addTarget:self
  73. action:@selector(stationButtonClicked:)
  74. forControlEvents:UIControlEventTouchUpInside
  75. ];
  76. }
  77. - (void) stationButtonClicked:(id)sender {
  78. [self showStationSheetAlert];
  79. }
  80. - (void) handleButtonClicked:(id)sender {
  81. if(self.station != nil && self.station.length > 0){
  82. //NSLog(@"test: %@", self.station);
  83. switch ([sender tag]) {
  84. case 0:
  85. //NSLog(@"button1 have been clicked.");
  86. {
  87. //查車
  88. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"InquireCar" bundle:[NSBundle mainBundle]];
  89. InquireCarViewController *InquireCarController = [storyboard instantiateViewControllerWithIdentifier:@"InquireCar"];
  90. [self.navigationController popViewControllerAnimated: YES];
  91. [self.navigationController pushViewController:InquireCarController animated:YES];
  92. }
  93. break;
  94. case 1:
  95. //NSLog(@"button2 have been clicked.");
  96. {
  97. //鎖車
  98. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"CarSecurity" bundle:[NSBundle mainBundle]];
  99. CarSecurityViewController *CarSecurityController = [storyboard instantiateViewControllerWithIdentifier:@"CarSecurity"];
  100. [self.navigationController popViewControllerAnimated: YES];
  101. CarSecurityController.station = self.station;
  102. [self.navigationController pushViewController:CarSecurityController animated:YES];
  103. }
  104. break;
  105. case 2:
  106. //NSLog(@"button3 have been clicked.");
  107. {
  108. //求助
  109. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Help" bundle:[NSBundle mainBundle]];
  110. HelpInfoViewController *HelpController = [storyboard instantiateViewControllerWithIdentifier:@"Help"];
  111. [self.navigationController popViewControllerAnimated: YES];
  112. [self.navigationController pushViewController:HelpController animated:YES];
  113. }
  114. break;
  115. case 3:
  116. //NSLog(@"button4 have been clicked.");
  117. {
  118. /*
  119. UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Payment" bundle:[NSBundle mainBundle]];
  120. PaymentViewController *PaymentController = [storyboard instantiateViewControllerWithIdentifier:@"Payment"];
  121. [self.navigationController popViewControllerAnimated: YES];
  122. [self.navigationController pushViewController:PaymentController animated:YES];
  123. */
  124. [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"https://parks.altob.com.tw/opay.html"] options:nil completionHandler:nil];
  125. }
  126. break;
  127. default:
  128. break;
  129. }
  130. }else{
  131. [self showAlert2: @"注意" : @"請先選擇場站" : 0];
  132. }
  133. }
  134. -(void)showAlert{
  135. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"重要"
  136. message:@"本APP將會使用您的網路連線功能和電話權限於緊急協助中撥打電話給場站。在任何傳輸的過程中也會對您的資料進行加密。如不同意的話則無法使用完整的App功能"
  137. preferredStyle:UIAlertControllerStyleAlert ];
  138. //添加确定到UIAlertController中
  139. UIAlertAction *sinupAction = [UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  140. [self.defaults setBool:YES forKey:@"notFirstRun"];
  141. }];
  142. [alertController addAction:sinupAction];
  143. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"不同意" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  144. [self.defaults setBool:NO forKey:@"notFirstRun"];
  145. exit(0);
  146. }];
  147. [alertController addAction:cancelAction];
  148. [self presentViewController:alertController animated:YES completion:nil];
  149. }
  150. -(void)showAlert2:(NSString *)title :(NSString *)text: (NSInteger *)type{
  151. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
  152. message:text
  153. preferredStyle:UIAlertControllerStyleAlert ];
  154. UIAlertAction *sinupAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  155. }];
  156. [alertController addAction:sinupAction];
  157. [self presentViewController:alertController animated:YES completion:nil];
  158. }
  159. -(void) showStationSheetAlert{
  160. // 創建一個UIAlertController, 命名為alertThree, preferredStyle 設置為 UIAlertControllerStyleActionSheet
  161. UIAlertController *alertThree = [UIAlertController alertControllerWithTitle:@"場站" message:@"請選擇所在場站:" preferredStyle:UIAlertControllerStyleActionSheet];
  162. // 創建一個“取消”按鈕
  163. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
  164. // 將按鈕添加到alertThree上
  165. [alertThree addAction:cancelAction];
  166. // 根據陣列資料創建選項按鈕
  167. for(int i = 0 ; i < self.StationData.count; i++){
  168. UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:[[self.StationData objectAtIndex:i] valueForKey:@"name"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  169. [self.stationName setText:[[self.StationData objectAtIndex:i] valueForKey:@"name"]];
  170. self.station = [[self.StationData objectAtIndex:i] valueForKey:@"code"];
  171. }];
  172. // 將按鈕添加到alertThree上
  173. [alertThree addAction:confirmAction];
  174. }
  175. alertThree.popoverPresentationController.sourceView = self.view;
  176. alertThree.popoverPresentationController.sourceRect = CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 1.0, 1.0);
  177. // 彈出alertThree
  178. [self presentViewController:alertThree animated:YES completion:nil];
  179. }
  180. //截屏响应
  181. - (void)userDidTakeScreenshot:(NSNotification *)notification
  182. {
  183. [self showAlert2: @"注意" : @"偵測到截圖,請妥善保管截圖,避免重要資訊外流" : 0];
  184. }
  185. @end