Showing
1 changed file
with
53 additions
and
40 deletions
| ... | @@ -116,32 +116,41 @@ import CoreMotion | ... | @@ -116,32 +116,41 @@ import CoreMotion | 
| 116 | // MARK: Actions | 116 | // MARK: Actions | 
| 117 | 117 | ||
| 118 | @IBAction private func tripButtonTapped(_ sender: UIButton) { | 118 | @IBAction private func tripButtonTapped(_ sender: UIButton) { | 
| 119 | - if (mIsTripStarted == true) { | 119 | + DispatchQueue.global().async { | 
| 120 | - // Stop trip | 120 | + if (!self.locationServicesIsEnabled()) { | 
| 121 | - stopTrip() | 121 | + self.onLocationServicesIsDisabled(); | 
| 122 | + return; | ||
| 123 | + } | ||
| 122 | 124 | ||
| 123 | - } else { | 125 | + DispatchQueue.main.async { | 
| 124 | - // Start trip | 126 | + if (mIsTripStarted == true) { | 
| 125 | -// if let limitText = accelerationLimitTextField.text, limitText.isEmpty { | 127 | + // Stop trip | 
| 126 | -// // Handle empty limit field | 128 | + stopTrip() | 
| 127 | -// return | 129 | + | 
| 128 | -// } | 130 | + } else { | 
| 129 | - | 131 | + // Start trip | 
| 130 | - // Disable UI elements | 132 | + // if let limitText = accelerationLimitTextField.text, limitText.isEmpty { | 
| 131 | -// accelerationLimitTextField.isEnabled = false | 133 | + // // Handle empty limit field | 
| 132 | -// sampleTimeTextField.isEnabled = false | 134 | + // return | 
| 133 | - | 135 | + // } | 
| 134 | - // Start location and sensor updates | 136 | + | 
| 135 | - requestLocationUpdates() | 137 | + // Disable UI elements | 
| 136 | -// registerSensor() | 138 | + // accelerationLimitTextField.isEnabled = false | 
| 137 | - | 139 | + // sampleTimeTextField.isEnabled = false | 
| 138 | - mIsTripStarted = true | 140 | + | 
| 139 | -// orientationCountLabel.text = "0" | 141 | + // Start location and sensor updates | 
| 140 | -// touchCountLabel.text = "0" | 142 | + requestLocationUpdates() | 
| 141 | - tripButton.setTitle("Stop Trip", for: .normal) | 143 | + // registerSensor() | 
| 142 | - mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970 | 144 | + | 
| 143 | - initializeOrientation() | 145 | + mIsTripStarted = true | 
| 144 | - startTimer() | 146 | + // orientationCountLabel.text = "0" | 
| 147 | + // touchCountLabel.text = "0" | ||
| 148 | + tripButton.setTitle("Stop Trip", for: .normal) | ||
| 149 | + mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970 | ||
| 150 | + initializeOrientation() | ||
| 151 | + startTimer() | ||
| 152 | + } | ||
| 153 | + } | ||
| 145 | } | 154 | } | 
| 146 | } | 155 | } | 
| 147 | 156 | ||
| ... | @@ -289,22 +298,26 @@ import CoreMotion | ... | @@ -289,22 +298,26 @@ import CoreMotion | 
| 289 | } | 298 | } | 
| 290 | 299 | ||
| 291 | private func requestLocationUpdates() { | 300 | private func requestLocationUpdates() { | 
| 292 | - if CLLocationManager.locationServicesEnabled() { | 301 | + DispatchQueue.global().async { | 
| 293 | - locationManager.desiredAccuracy = kCLLocationAccuracyBest | 302 | + if CLLocationManager.locationServicesEnabled() { | 
| 294 | -// locationManager.requestLocation() | 303 | + locationManager.desiredAccuracy = kCLLocationAccuracyBest | 
| 295 | - | 304 | + // locationManager.requestLocation() | 
| 296 | - if (!locationServicesIsEnabled()) { | 305 | + | 
| 297 | - onLocationServicesIsDisabled(); | 306 | + if (!locationServicesIsEnabled()) { | 
| 298 | - } | 307 | + onLocationServicesIsDisabled(); | 
| 299 | - else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) { | 308 | + } | 
| 300 | - onAuthorizationStatusIsDenied(); | 309 | + else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) { | 
| 301 | - } | 310 | + onAuthorizationStatusIsDenied(); | 
| 302 | - else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) { | 311 | + } | 
| 303 | - onAuthorizationStatusNeedRequest(); | 312 | + else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) { | 
| 304 | - } | 313 | + onAuthorizationStatusNeedRequest(); | 
| 305 | - else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) { | 314 | + } | 
| 306 | - onAuthorizationStatusIsGranted(); | 315 | + else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) { | 
| 316 | + onAuthorizationStatusIsGranted(); | ||
| 317 | + } | ||
| 307 | } | 318 | } | 
| 319 | + } else { | ||
| 320 | + self.onLocationServicesIsDisabled(); | ||
| 308 | } | 321 | } | 
| 309 | } | 322 | } | 
| 310 | 323 | ... | ... | 
- 
Please register or login to post a comment