Showing
1 changed file
with
37 additions
and
24 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 | + if (!self.locationServicesIsEnabled()) { | ||
121 | + self.onLocationServicesIsDisabled(); | ||
122 | + return; | ||
123 | + } | ||
124 | + | ||
125 | + DispatchQueue.main.async { | ||
126 | + if (self.mIsTripStarted == true) { | ||
120 | // Stop trip | 127 | // Stop trip |
121 | - stopTrip() | 128 | + self.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 = self.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 | + self.accelerationLimitTextField.isEnabled = false |
132 | - sampleTimeTextField.isEnabled = false | 139 | + self.sampleTimeTextField.isEnabled = false |
133 | 140 | ||
134 | // Start location and sensor updates | 141 | // Start location and sensor updates |
135 | - requestLocationUpdates() | 142 | + self.requestLocationUpdates() |
136 | -// registerSensor() | 143 | + // registerSensor() |
137 | 144 | ||
138 | - mIsTripStarted = true | 145 | + self.mIsTripStarted = true |
139 | - orientationCountLabel.text = "0" | 146 | + self.orientationCountLabel.text = "0" |
140 | - touchCountLabel.text = "0" | 147 | + self.touchCountLabel.text = "0" |
141 | - tripButton.setTitle("Stop Trip", for: .normal) | 148 | + self.tripButton.setTitle("Stop Trip", for: .normal) |
142 | - mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970 | 149 | + self.mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970 |
143 | - initializeOrientation() | 150 | + self.initializeOrientation() |
144 | - startTimer() | 151 | + self.startTimer() |
152 | + } | ||
153 | + } | ||
145 | } | 154 | } |
146 | } | 155 | } |
147 | 156 | ||
... | @@ -289,21 +298,25 @@ import CoreMotion | ... | @@ -289,21 +298,25 @@ 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 | + self.locationManager.desiredAccuracy = kCLLocationAccuracyBest |
294 | -// locationManager.requestLocation() | 304 | + // locationManager.requestLocation() |
295 | 305 | ||
296 | - if (!locationServicesIsEnabled()) { | 306 | + if (!self.locationServicesIsEnabled()) { |
297 | - onLocationServicesIsDisabled(); | 307 | + self.onLocationServicesIsDisabled(); |
298 | } | 308 | } |
299 | - else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) { | 309 | + else if (self.authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) { |
300 | - onAuthorizationStatusIsDenied(); | 310 | + self.onAuthorizationStatusIsDenied(); |
301 | } | 311 | } |
302 | - else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) { | 312 | + else if (self.authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) { |
303 | - onAuthorizationStatusNeedRequest(); | 313 | + self.onAuthorizationStatusNeedRequest(); |
304 | } | 314 | } |
305 | - else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) { | 315 | + else if (self.authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) { |
306 | - onAuthorizationStatusIsGranted(); | 316 | + self.onAuthorizationStatusIsGranted(); |
317 | + } | ||
318 | + } else { | ||
319 | + self.onLocationServicesIsDisabled(); | ||
307 | } | 320 | } |
308 | } | 321 | } |
309 | } | 322 | } | ... | ... |
-
Please register or login to post a comment