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