Manos Chorianopoulos

locationServices enable request fix

...@@ -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 (self.mIsTripStarted == true) {
125 - if let limitText = accelerationLimitTextField.text, limitText.isEmpty { 127 + // Stop trip
126 - // Handle empty limit field 128 + self.stopTrip()
127 - return 129 +
130 + } else {
131 + // Start trip
132 + if let limitText = self.accelerationLimitTextField.text, limitText.isEmpty {
133 + // Handle empty limit field
134 + return
135 + }
136 +
137 + // Disable UI elements
138 + self.accelerationLimitTextField.isEnabled = false
139 + self.sampleTimeTextField.isEnabled = false
140 +
141 + // Start location and sensor updates
142 + self.requestLocationUpdates()
143 + // registerSensor()
144 +
145 + self.mIsTripStarted = true
146 + self.orientationCountLabel.text = "0"
147 + self.touchCountLabel.text = "0"
148 + self.tripButton.setTitle("Stop Trip", for: .normal)
149 + self.mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970
150 + self.initializeOrientation()
151 + self.startTimer()
152 + }
128 } 153 }
129 -
130 - // Disable UI elements
131 - accelerationLimitTextField.isEnabled = false
132 - sampleTimeTextField.isEnabled = false
133 -
134 - // Start location and sensor updates
135 - requestLocationUpdates()
136 -// registerSensor()
137 -
138 - mIsTripStarted = true
139 - orientationCountLabel.text = "0"
140 - touchCountLabel.text = "0"
141 - tripButton.setTitle("Stop Trip", for: .normal)
142 - mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970
143 - initializeOrientation()
144 - startTimer()
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() {
292 - if CLLocationManager.locationServicesEnabled() { 301 + DispatchQueue.global().async {
293 - locationManager.desiredAccuracy = kCLLocationAccuracyBest 302 + if CLLocationManager.locationServicesEnabled() {
294 -// locationManager.requestLocation() 303 + self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
295 - 304 + // locationManager.requestLocation()
296 - if (!locationServicesIsEnabled()) { 305 +
297 - onLocationServicesIsDisabled(); 306 + if (!self.locationServicesIsEnabled()) {
298 - } 307 + self.onLocationServicesIsDisabled();
299 - else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) { 308 + }
300 - onAuthorizationStatusIsDenied(); 309 + else if (self.authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) {
301 - } 310 + self.onAuthorizationStatusIsDenied();
302 - else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) { 311 + }
303 - onAuthorizationStatusNeedRequest(); 312 + else if (self.authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) {
304 - } 313 + self.onAuthorizationStatusNeedRequest();
305 - else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) { 314 + }
306 - onAuthorizationStatusIsGranted(); 315 + else if (self.authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) {
316 + self.onAuthorizationStatusIsGranted();
317 + }
318 + } else {
319 + self.onLocationServicesIsDisabled();
307 } 320 }
308 } 321 }
309 } 322 }
......