Showing
4 changed files
with
21 additions
and
12 deletions
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>1</integer> | 10 | + <integer>0</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>0</integer> | 10 | + <integer>1</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
No preview for this file type
| ... | @@ -14,6 +14,8 @@ import CoreMotion | ... | @@ -14,6 +14,8 @@ import CoreMotion |
| 14 | // MARK: Constants and Properties | 14 | // MARK: Constants and Properties |
| 15 | 15 | ||
| 16 | private var mIsTripStarted = false | 16 | private var mIsTripStarted = false |
| 17 | + private var hasLocationPermissions = false | ||
| 18 | + private var isFirstLoad = true | ||
| 17 | private var mAccelerationTimestamps = [[String: Any]]() | 19 | private var mAccelerationTimestamps = [[String: Any]]() |
| 18 | private var locationManager: CLLocationManager! | 20 | private var locationManager: CLLocationManager! |
| 19 | private var motionManager: CMMotionManager! | 21 | private var motionManager: CMMotionManager! |
| ... | @@ -68,6 +70,8 @@ import CoreMotion | ... | @@ -68,6 +70,8 @@ import CoreMotion |
| 68 | accelerationLimitTextField.delegate = self | 70 | accelerationLimitTextField.delegate = self |
| 69 | sampleTimeTextField.delegate = self | 71 | sampleTimeTextField.delegate = self |
| 70 | 72 | ||
| 73 | + hasLocationPermissions = authorizationStatusIsGranted(status: CLLocationManager.authorizationStatus()) | ||
| 74 | + | ||
| 71 | orientationCountLabel.text = "0" | 75 | orientationCountLabel.text = "0" |
| 72 | touchCountLabel.text = "0" | 76 | touchCountLabel.text = "0" |
| 73 | recordsSavedLabel.text = "0" | 77 | recordsSavedLabel.text = "0" |
| ... | @@ -99,7 +103,7 @@ import CoreMotion | ... | @@ -99,7 +103,7 @@ import CoreMotion |
| 99 | 103 | ||
| 100 | public override func viewWillDisappear(_ animated: Bool) { | 104 | public override func viewWillDisappear(_ animated: Bool) { |
| 101 | super.viewWillDisappear(animated) | 105 | super.viewWillDisappear(animated) |
| 102 | - | 106 | + |
| 103 | if (self.mIsTripStarted == true) { | 107 | if (self.mIsTripStarted == true) { |
| 104 | self.stopTrip() | 108 | self.stopTrip() |
| 105 | } | 109 | } |
| ... | @@ -234,7 +238,7 @@ import CoreMotion | ... | @@ -234,7 +238,7 @@ import CoreMotion |
| 234 | } | 238 | } |
| 235 | 239 | ||
| 236 | private func processAccelerometerData(_ accelerationData: CMAccelerometerData) { | 240 | private func processAccelerometerData(_ accelerationData: CMAccelerometerData) { |
| 237 | - // print("=== accelerationData: ",accelerationData) | 241 | + // print("=== accelerationData: ",accelerationData) |
| 238 | 242 | ||
| 239 | // sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)" | 243 | // sensorDataLabel.text = "\(accelerationData.acceleration.x), \(accelerationData.acceleration.y), \(accelerationData.acceleration.z)" |
| 240 | 244 | ||
| ... | @@ -260,7 +264,7 @@ import CoreMotion | ... | @@ -260,7 +264,7 @@ import CoreMotion |
| 260 | // TODO: CHECK mayby this is correct | 264 | // TODO: CHECK mayby this is correct |
| 261 | // accelerationLabel.text = String(format: "%.1f m/s^2", acceleration) | 265 | // accelerationLabel.text = String(format: "%.1f m/s^2", acceleration) |
| 262 | 266 | ||
| 263 | - // print("=== acceleration: ",acceleration) | 267 | + // print("=== acceleration: ",acceleration) |
| 264 | 268 | ||
| 265 | // If acceleration is below the stop threshold, assume we are in a stop | 269 | // If acceleration is below the stop threshold, assume we are in a stop |
| 266 | // if acceleration < STOP_THRESHOLD { | 270 | // if acceleration < STOP_THRESHOLD { |
| ... | @@ -270,7 +274,7 @@ import CoreMotion | ... | @@ -270,7 +274,7 @@ import CoreMotion |
| 270 | velocity = acceleration * time | 274 | velocity = acceleration * time |
| 271 | // } | 275 | // } |
| 272 | 276 | ||
| 273 | - // print("=== velocity: ",velocity) | 277 | + // print("=== velocity: ",velocity) |
| 274 | 278 | ||
| 275 | // Convert velocity to km/h | 279 | // Convert velocity to km/h |
| 276 | mAcceleration = velocity // Convert to km/h | 280 | mAcceleration = velocity // Convert to km/h |
| ... | @@ -400,7 +404,7 @@ import CoreMotion | ... | @@ -400,7 +404,7 @@ import CoreMotion |
| 400 | 404 | ||
| 401 | self?.mAccelerationTimestamps.append(jsonObject) | 405 | self?.mAccelerationTimestamps.append(jsonObject) |
| 402 | 406 | ||
| 403 | - // print("=== self?.mAccelerationTimestamps: ", self?.mAccelerationTimestamps) | 407 | + // print("=== self?.mAccelerationTimestamps: ", self?.mAccelerationTimestamps) |
| 404 | } | 408 | } |
| 405 | } | 409 | } |
| 406 | timerTel!.resume() | 410 | timerTel!.resume() |
| ... | @@ -449,9 +453,14 @@ import CoreMotion | ... | @@ -449,9 +453,14 @@ import CoreMotion |
| 449 | } | 453 | } |
| 450 | 454 | ||
| 451 | func onAuthorizationStatusIsGranted() { | 455 | func onAuthorizationStatusIsGranted() { |
| 452 | - // print("=== onAuthorizationStatusIsGranted === ") | 456 | + // print("=== onAuthorizationStatusIsGranted === ") |
| 453 | locationManager.startUpdatingLocation(); | 457 | locationManager.startUpdatingLocation(); |
| 454 | - registerSensor() | 458 | +// registerSensor() |
| 459 | + if (!isFirstLoad || (isFirstLoad && !hasLocationPermissions)) { | ||
| 460 | + registerSensor() | ||
| 461 | + } | ||
| 462 | + hasLocationPermissions = true | ||
| 463 | + isFirstLoad = false | ||
| 455 | } | 464 | } |
| 456 | 465 | ||
| 457 | func onAuthorizationStatusIsDenied() { | 466 | func onAuthorizationStatusIsDenied() { |
| ... | @@ -459,7 +468,7 @@ import CoreMotion | ... | @@ -459,7 +468,7 @@ import CoreMotion |
| 459 | } | 468 | } |
| 460 | 469 | ||
| 461 | public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { | 470 | public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { |
| 462 | - // print("=== locationManager didChangeAuthorization: ",status) | 471 | + // print("=== locationManager didChangeAuthorization: ",status) |
| 463 | 472 | ||
| 464 | if (authorizationStatusIsDenied(status: status)) { | 473 | if (authorizationStatusIsDenied(status: status)) { |
| 465 | onAuthorizationStatusIsDenied(); | 474 | onAuthorizationStatusIsDenied(); |
| ... | @@ -471,8 +480,8 @@ import CoreMotion | ... | @@ -471,8 +480,8 @@ import CoreMotion |
| 471 | 480 | ||
| 472 | public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | 481 | public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
| 473 | if let location = locations.last { | 482 | if let location = locations.last { |
| 474 | - // print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude) | 483 | + // print("=== locationManager didUpdateLocations latitude: ",location.coordinate.latitude) |
| 475 | - // print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude) | 484 | + // print("=== locationManager didUpdateLocations longitude: ",location.coordinate.longitude) |
| 476 | 485 | ||
| 477 | if mLatitude != 0 && mLongitude != 0 { | 486 | if mLatitude != 0 && mLongitude != 0 { |
| 478 | mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000) | 487 | mSpeed = calculateSpeed(lat1: mLatitude, lon1: mLongitude, lat2: location.coordinate.latitude, lon2: location.coordinate.longitude, timeDifferenceInSeconds: LOCATION_UPDATE_INTERVAL / 1000) | ... | ... |
-
Please register or login to post a comment