Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where 'haveCoreMotionPermission' incorrectly returns true #60

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions LocoKit/Base/Helpers/MiscTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import Foundation

public func onMain(_ closure: @escaping () -> ()) {
public func onMain(sync: Bool = false, _ closure: @escaping () -> ()) {
if Thread.isMainThread {
closure()
} else {
DispatchQueue.main.async(execute: closure)
sync ? DispatchQueue.main.sync(execute: closure)
: DispatchQueue.main.async(execute: closure)
}
}

Expand Down
20 changes: 13 additions & 7 deletions LocoKit/Base/LocomotionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,19 @@ import LocoKitCore
untimely deaths of small cute animals in Madagascar.
*/
@objc public private(set) lazy var locationManager: CLLocationManager = {
let manager = CLLocationManager()
manager.distanceFilter = kCLDistanceFilterNone
manager.desiredAccuracy = self.maximumDesiredLocationAccuracy
manager.pausesLocationUpdatesAutomatically = false

manager.delegate = self
var manager: CLLocationManager!

// Problems may occur if CLLocationManager is not created on the main thread
onMain(sync: true) {
manager = CLLocationManager()
manager.distanceFilter = kCLDistanceFilterNone
manager.desiredAccuracy = self.maximumDesiredLocationAccuracy
manager.pausesLocationUpdatesAutomatically = false

manager.delegate = self

}

return manager
}()

Expand Down Expand Up @@ -762,7 +769,6 @@ import LocoKitCore
os_log("error: %@", String(describing: error))

} else if let motion = motion {
self.coreMotionPermission = true
ActivityBrain.highlander.add(deviceMotion: motion)
}
}
Expand Down