Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import Foundation

extension CMAccelerometerData {
/**
Get the current device orientation from the given acceleration/gyro data.
Get the current device orientation from the given acceleration/gyro data, or `nil` if it is unknown.
The orientation can only be unknown if the phone is flat, in which case it is not clear which orientation the phone is held in.
*/
var deviceOrientation: Orientation {
var deviceOrientation: Orientation? {
let acceleration = acceleration
let xNorm = abs(acceleration.x)
let yNorm = abs(acceleration.y)
Expand Down
9 changes: 7 additions & 2 deletions package/ios/Core/OrientationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ final class OrientationManager {
stopDeviceOrientationListener()
if motionManager.isAccelerometerAvailable {
motionManager.accelerometerUpdateInterval = 0.2
motionManager.startAccelerometerUpdates(to: operationQueue) { accelerometerData, error in
motionManager.startAccelerometerUpdates(to: operationQueue) { [weak self] accelerometerData, error in
guard let self else { return }
if let error {
VisionLogger.log(level: .error, message: "Failed to get Accelerometer data! \(error)")
}
if let accelerometerData {
self.deviceOrientation = accelerometerData.deviceOrientation
// There is accelerometer data available
if let deviceOrientation = accelerometerData.deviceOrientation {
// The orientation can actually be determined - it is not `nil` (flat)! Update it
self.deviceOrientation = deviceOrientation
}
}
}
}
Expand Down
Loading