Manos Chorianopoulos

locationServices enable request fix TelematicsMain

......@@ -116,32 +116,41 @@ import CoreMotion
// MARK: Actions
@IBAction private func tripButtonTapped(_ sender: UIButton) {
if (mIsTripStarted == true) {
// Stop trip
stopTrip()
DispatchQueue.global().async {
if (!self.locationServicesIsEnabled()) {
self.onLocationServicesIsDisabled();
return;
}
} else {
// Start trip
// if let limitText = accelerationLimitTextField.text, limitText.isEmpty {
// // Handle empty limit field
// return
// }
// Disable UI elements
// accelerationLimitTextField.isEnabled = false
// sampleTimeTextField.isEnabled = false
// Start location and sensor updates
requestLocationUpdates()
// registerSensor()
mIsTripStarted = true
// orientationCountLabel.text = "0"
// touchCountLabel.text = "0"
tripButton.setTitle("Stop Trip", for: .normal)
mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970
initializeOrientation()
startTimer()
DispatchQueue.main.async {
if (mIsTripStarted == true) {
// Stop trip
stopTrip()
} else {
// Start trip
// if let limitText = accelerationLimitTextField.text, limitText.isEmpty {
// // Handle empty limit field
// return
// }
// Disable UI elements
// accelerationLimitTextField.isEnabled = false
// sampleTimeTextField.isEnabled = false
// Start location and sensor updates
requestLocationUpdates()
// registerSensor()
mIsTripStarted = true
// orientationCountLabel.text = "0"
// touchCountLabel.text = "0"
tripButton.setTitle("Stop Trip", for: .normal)
mStartTimestamp = String(Int(Date().timeIntervalSince1970 * 1000)) // time in milliseconds since January 1, 1970
initializeOrientation()
startTimer()
}
}
}
}
......@@ -289,22 +298,26 @@ import CoreMotion
}
private func requestLocationUpdates() {
if CLLocationManager.locationServicesEnabled() {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
// locationManager.requestLocation()
if (!locationServicesIsEnabled()) {
onLocationServicesIsDisabled();
}
else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusIsDenied();
}
else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusNeedRequest();
}
else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusIsGranted();
DispatchQueue.global().async {
if CLLocationManager.locationServicesEnabled() {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
// locationManager.requestLocation()
if (!locationServicesIsEnabled()) {
onLocationServicesIsDisabled();
}
else if (authorizationStatusIsDenied(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusIsDenied();
}
else if (authorizationStatusNeedRequest(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusNeedRequest();
}
else if (authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus())) {
onAuthorizationStatusIsGranted();
}
}
} else {
self.onLocationServicesIsDisabled();
}
}
......